我正在使用shell脚本删除我的Linux机器中的日志文件。我已经使用crontab定期执行这项工作。我可以手动执行这个脚本,看看它工作正常。但脚本不是通过cron作业触发的。Shell脚本手动运行,但不通过cron作业执行
外壳脚本:
[根@ testVM-dev的日志]#VIM /path_to_dir/log_cleanup.sh
#!/bin/bash
now=$(date)
echo "Cron Job to delete log files [email protected] $now" | tee -a /path_to_dir/log/cronjob_log.log
/usr/bin/find /path_to_dir/log/localhost_access_log.* -type f -mtime +5 -print -delete | tee -a /path_to_dir/log/cronjob_log.log
echo "Delete files completed!" | tee -a /path_to_dir/log/cronjob_log.log
crontab条目:(试验每分钟)
[[email protected] log]# crontab -l
*/1 * * * * root /path_to_dir/log_cleanup.sh
此外,我已经在cron日志中检查了每分钟执行一次作业。但我看不出有针对性的日志文件中的任何日志 “cronjob_log.log”
的cron日志:
VIM /无功/日志/ cron的
Jul 16 03:56:01 rstestVM-dev crond[19131]: (root) CMD (root /path_to_dir/log_cleanup.sh)
Jul 16 03:57:01 rstestVM-dev crond[19150]: (root) CMD (root /path_to_dir/log_cleanup.sh)
Jul 16 03:58:01 rstestVM-dev crond[19168]: (root) CMD (root /path_to_dir/log_cleanup.sh)
Jul 16 03:59:01 rstestVM-dev crond[19188]: (root) CMD (root /path_to_dir/log_cleanup.sh)
谁能帮我在这里出了什么问题?
你可以增加一段时间间隔,看看究竟发生了什么 – Satya
你的意思是将频率从1分钟增加到更多(如5分钟左右)? – svjn
是的,尝试将它添加到5分钟,然后看到 – Satya