【发布时间】:2013-01-02 01:04:20
【问题描述】:
GNU nano 2.0.9 文件:/tmp/crontab.XXXXzBQgwS
*/5 * * * * ~/check_phpfpm.sh
*/5 * * * * ~/check_nginx.sh
*/5 * * * * ~/disk-clean.sh
*/5 * * * * ~/loadcheck.sh
我的代码应该每 5 分钟运行一次。但它没有运行
[root@4D13 ~]# ls -l
total 756
-rw-------. 1 root root 1688 Dec 18 09:45 anaconda-ks.cfg
-rwxrwxrwx 1 root root 139 Dec 28 18:18 check_nginx.sh
-rwxrwxrwx 1 root root 140 Dec 28 18:19 check_phpfpm.sh
-rwxrwxrwx 1 root root 456 Dec 28 18:18 disk-clean.sh
-rw-r--r--. 1 root root 15469 Dec 18 09:45 install.log
-rw-r--r--. 1 root root 5267 Dec 18 09:44 install.log.syslog
-rwxrwxrwx 1 root root 503 Dec 19 19:26 loadcheck.sh
drwxr-xr-x 9 1001 1001 4096 Dec 18 11:08 nginx-1.3.2
-rw-r--r-- 1 root root 722119 Jun 26 2012 nginx-1.3.2.tar.gz
[root@4D13 ~]#
它应该运行 ~/check_phpfpm.sh 作为我的代码,如果我手动运行它会工作
[root@4D13 ~]#
[root@4D13 ~]# ~/check_phpfpm.sh
Stopping php-fpm: [FAILED]
Starting php-fpm: [ OK ]
关于 check_phpfpm 的更多信息,它是一个检查服务 php-fpm 是否正在运行的脚本,如果它不工作,它将执行并重新启动 php-fpm,但问题是如果我手动运行它的工作。但是 crontab 没有重新启动,服务器 php-fpm 崩溃并进入停止模式,但是这个脚本没有重新启动,我的 crontab 应该每 5 分钟执行一次脚本来检查。
我的 crontab 设置有什么问题?感谢大家的帮助
【问题讨论】:
-
Cron 通常会向您发送有关其输出的电子邮件。您可以使用本地系统上的邮件查看您的电子邮件吗?
-
为什么不直接查看 /var/log 中的日志文件?
-
两个常见问题:未设置环境(PATH 等)或未使用预期的 shell...在 cron 下两者的默认值都非常小。从命令行运行但不在 cron 下运行是这种情况的典型症状。快速测试: */5 * * * * 。 ~/.profile && your_command
-
不要对 cronjobs 中的当前目录或 PATH 设置做任何假设。相反,明确地设置它们。另外:我认为波浪号不会被扩展,请使用显式路径(例如 /home/root/myscript.sh )
-
谁的 crontab 是谁运行的?我看到日志文件是由 root 拥有的,所以在 crontab 中,
~是什么?