首页 > 解决方案 > 为什么我的 crontab 不能使用 /etc/crontab 文件

问题描述

在我的项目中,我想用 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)

谁能帮我?

标签: cron

解决方案


crontab -l 给出输出“root 没有 crontab”。这是意料之中的,因为它只会显示使用命令 crontab -e 添加的 crontab。在“/etc/crontab”中添加的 crons 不会在 crontab -l 命令中列出。

要检查的东西。1、检查文件“/home/JobidUserJobname/JobidUserJobname.sh”是否有执行权限。如果否,则执行以下命令。

chmod +x /home/JobidUserJobname/JobidUserJobname.sh
  1. 如果它仍然无法正常工作,请在脚本前添加“/bin/sh”。

    */10 * * * * 根 /bin/sh /home/JobidUserJobname/JobidUserJobname.sh

  2. 检查 cron 日志以查看是否有任何错误。


推荐阅读