在我的项目中,我想用cron做一个计划任务。
所以我在/etc/crontab 中添加了一行
*/10 * * * * root /home/JobidUserJobname/JobidUserJobname.sh
而/etc/crontab 的内容是这样的:
SHELL=/bin/bash
PATH=/sbin:/bin:/usr/sbin:/usr/bin
MAILTO=root
HOME=/
# For details see man 4 crontabs
# Example of job definition:
# .---------------- minute (0 - 59)
# | .------------- hour (0 - 23)
# | | .---------- day of month (1 - 31)
# | | | .------- month (1 - 12) OR jan,feb,mar,apr ...
# | | | | .---- day of week (0 - 6) (Sunday=0 or 7) OR sun,mon,tue,wed,thu,fri,sat
# | | | | |
# * * * * * user-name command to be executed
*/10 * * * * root /home/JobidUserJobname/JobidUserJobname.sh
*/1 * * * * root date
我重新启动了 crontab 服务:
#service crond restart
#service crond reload
他们成功执行。
但是当我执行时:
#crontab -l
它显示:
no crontab for root
似乎没什么不对。我的 Linux 操作系统是:
CentOS release 6.5 (Final)
谁能帮助我?
crontab -l 给出输出 "no crontab for root"。这是意料之中的,因为它将仅显示使用命令 crontab -e 添加的 crontab。在 "/etc/crontab" 中添加的 crons 将不会在 crontab -l 命令中列出。
要检查的事情。1. 检查文件"/home/JobidUserJobname/JobidUserJobname.sh"是否有执行权限。如果没有,则执行以下命令。
chmod +x /home/JobidUserJobname/JobidUserJobname.sh
如果它仍然不起作用,请在脚本之前附加一个"/bin/sh"。
*/10 * * * * 根/bin/sh/home/JobidUserJobname/JobidUserJobname.sh
检查 cron 日志以查看是否有任何错误。