Crontab 正在运行,但我的脚本不会在 cron 中加载
Cronjob is working, but my Script wont load in cron
我的 cron 正在运行(下面的 Cron.log)并且我的脚本也在运行。但是 Cron 不会每 2 分钟加载一次脚本。
Cron.log:
Apr 3 01:02:01 Debian-78-wheezy-64-minimal /USR/SBIN/CRON[11777]: (mc) CMD (mc /home/mctw2/crash-script)
Apr 3 01:04:01 Debian-78-wheezy-64-minimal /USR/SBIN/CRON[1754]: (mc) CMD (mc /home/mctw2/crash-script)
Apr 3 01:06:01 Debian-78-wheezy-64-minimal /USR/SBIN/CRON[15086]: (mc) CMD (mc /home/mctw2/crash-script)
Apr 3 01:06:49 Debian-78-wheezy-64-minimal crontab[5657]: (root) BEGIN EDIT (root)
Apr 3 01:06:54 Debian-78-wheezy-64-minimal crontab[5657]: (root) END EDIT (root)
Apr 3 01:06:59 Debian-78-wheezy-64-minimal crontab[19549]: (mc) BEGIN EDIT (mc)
Apr 3 01:08:01 Debian-78-wheezy-64-minimal /USR/SBIN/CRON[9566]: (mc) CMD (mc /home/mctw2/crash-script)
Apr 3 01:08:21 Debian-78-wheezy-64-minimal crontab[19549]: (mc) END EDIT (mc)
Apr 3 01:08:26 Debian-78-wheezy-64-minimal crontab[12341]: (mc) BEGIN EDIT (mc)
Apr 3 01:09:01 Debian-78-wheezy-64-minimal /USR/SBIN/CRON[7312]: (root) CMD ( [ -x /usr/lib/php5/maxlifetime ] && [ -x /usr/lib/php5/sessionclean ] && [ -d /var/lib/php5 ] && /usr/lib/php5/sessionclean /var/lib/php5 $(/usr/lib/php5/maxlifetime))
Apr 3 01:10:01 Debian-78-wheezy-64-minimal /USR/SBIN/CRON[29224]: (mc) CMD (mc /home/mctw2/crash-script)
Apr 3 01:10:45 Debian-78-wheezy-64-minimal crontab[12341]: (mc) END EDIT (mc)
Apr 3 01:12:01 Debian-78-wheezy-64-minimal /USR/SBIN/CRON[4285]: (mc) CMD (mc /home/mctw2/crash-script)
Apr 3 01:14:01 Debian-78-wheezy-64-minimal /USR/SBIN/CRON[12549]: (mc) CMD (mc /home/mctw2/crash-script)
Apr 3 01:16:01 Debian-78-wheezy-64-minimal /USR/SBIN/CRON[2767]: (mc) CMD (mc /home/mctw2/crash-script)
Apr 3 01:17:01 Debian-78-wheezy-64-minimal /USR/SBIN/CRON[18323]: (root) CMD ( cd / && run-parts --report /etc/cron.hourly)
这是我的脚本:
#!/bin/bash
SERVER=`ps ax | grep FTBServer-1.6.4-965.jar | grep -v grep | wc -l`
if [ $SERVER -eq 1 ]
then
exit
else
cd /home/mctw2/ ; screen -a -m -d -s mctw2 ./ServerStart.sh
fi
至少还有我的 crontab:
*/2 * * * * mc /home/mctw2/crash-script
我怎样才能让它发挥作用?
您的 crontab 条目
*/2 * * * * mc /home/mctw2/crash-script
在第 6 列中包含用户名 mc
,适用于 /etc/crontab
.
中的系统级 crontab
然而,使用 crontab -e
编辑的每用户 crontab 的格式如下:
*/2 * * * * /home/mctw2/crash-script
我的 cron 正在运行(下面的 Cron.log)并且我的脚本也在运行。但是 Cron 不会每 2 分钟加载一次脚本。
Cron.log:
Apr 3 01:02:01 Debian-78-wheezy-64-minimal /USR/SBIN/CRON[11777]: (mc) CMD (mc /home/mctw2/crash-script)
Apr 3 01:04:01 Debian-78-wheezy-64-minimal /USR/SBIN/CRON[1754]: (mc) CMD (mc /home/mctw2/crash-script)
Apr 3 01:06:01 Debian-78-wheezy-64-minimal /USR/SBIN/CRON[15086]: (mc) CMD (mc /home/mctw2/crash-script)
Apr 3 01:06:49 Debian-78-wheezy-64-minimal crontab[5657]: (root) BEGIN EDIT (root)
Apr 3 01:06:54 Debian-78-wheezy-64-minimal crontab[5657]: (root) END EDIT (root)
Apr 3 01:06:59 Debian-78-wheezy-64-minimal crontab[19549]: (mc) BEGIN EDIT (mc)
Apr 3 01:08:01 Debian-78-wheezy-64-minimal /USR/SBIN/CRON[9566]: (mc) CMD (mc /home/mctw2/crash-script)
Apr 3 01:08:21 Debian-78-wheezy-64-minimal crontab[19549]: (mc) END EDIT (mc)
Apr 3 01:08:26 Debian-78-wheezy-64-minimal crontab[12341]: (mc) BEGIN EDIT (mc)
Apr 3 01:09:01 Debian-78-wheezy-64-minimal /USR/SBIN/CRON[7312]: (root) CMD ( [ -x /usr/lib/php5/maxlifetime ] && [ -x /usr/lib/php5/sessionclean ] && [ -d /var/lib/php5 ] && /usr/lib/php5/sessionclean /var/lib/php5 $(/usr/lib/php5/maxlifetime))
Apr 3 01:10:01 Debian-78-wheezy-64-minimal /USR/SBIN/CRON[29224]: (mc) CMD (mc /home/mctw2/crash-script)
Apr 3 01:10:45 Debian-78-wheezy-64-minimal crontab[12341]: (mc) END EDIT (mc)
Apr 3 01:12:01 Debian-78-wheezy-64-minimal /USR/SBIN/CRON[4285]: (mc) CMD (mc /home/mctw2/crash-script)
Apr 3 01:14:01 Debian-78-wheezy-64-minimal /USR/SBIN/CRON[12549]: (mc) CMD (mc /home/mctw2/crash-script)
Apr 3 01:16:01 Debian-78-wheezy-64-minimal /USR/SBIN/CRON[2767]: (mc) CMD (mc /home/mctw2/crash-script)
Apr 3 01:17:01 Debian-78-wheezy-64-minimal /USR/SBIN/CRON[18323]: (root) CMD ( cd / && run-parts --report /etc/cron.hourly)
这是我的脚本:
#!/bin/bash
SERVER=`ps ax | grep FTBServer-1.6.4-965.jar | grep -v grep | wc -l`
if [ $SERVER -eq 1 ]
then
exit
else
cd /home/mctw2/ ; screen -a -m -d -s mctw2 ./ServerStart.sh
fi
至少还有我的 crontab:
*/2 * * * * mc /home/mctw2/crash-script
我怎样才能让它发挥作用?
您的 crontab 条目
*/2 * * * * mc /home/mctw2/crash-script
在第 6 列中包含用户名 mc
,适用于 /etc/crontab
.
然而,使用 crontab -e
编辑的每用户 crontab 的格式如下:
*/2 * * * * /home/mctw2/crash-script