cron - 为什么我的 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)
谁能帮我?
解决方案
crontab -l 给出输出“root 没有 crontab”。这是意料之中的,因为它只会显示使用命令 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 日志以查看是否有任何错误。
推荐阅读
- python - Django - 创建和搜索自定义用户模型
- c++ - 声明但不定义未使用的函数是否合法?
- php - 此代码是否有错误,因为它正确输出成功消息但数据库中没有任何更新
- python - KeyError: 1 问题,有什么问题?
- java - 代码完成后输出一堆零
- google-maps - 在 Private Google Access 环境中为我们限制 Google Maps API 密钥
- c# - 成功身份验证后,客户端浏览器被重定向回 ADFS 服务
- php - CRUD 中的 PHP 删除不会从数据库中删除项目
- java - 添加工具栏后android应用程序崩溃
- asp.net-identity - IdentityServer4 - 谷歌浏览器没有删除所有 cookie