clear_log.sh 493 B

12345678910111213141516171819202122232425262728
  1. #!/bin/bash
  2. set -e
  3. if [ $UID -ne 0 ]; then
  4. echo "请用root用户运行当前脚本 (su root)" && exit 1
  5. fi
  6. base_dir=$(
  7. cd "$(dirname "$0")"
  8. pwd
  9. )
  10. cd $base_dir
  11. if [[ -z $base_dir ]]; then
  12. echo "base_dir is empty, exit"
  13. exit 1
  14. fi
  15. log_path="$base_dir/log/**"
  16. read -p "Are you sure you want to remove all log files? (y/n): " confirm
  17. if [[ $confirm == [yY] ]]; then
  18. rm -rf $log_path
  19. echo "All log files have been removed."
  20. else
  21. echo "Operation cancelled."
  22. fi