【问题标题】:Cron job does not run in RHELCron 作业不在 RHEL 中运行
【发布时间】:2015-01-17 20:23:49
【问题描述】:

我正在运行 RHEL,我正在尝试设置一个 cron 作业以每 5 分钟运行一次 shell 脚本。

按照这里的指示:https://access.redhat.com/documentation/en-US/Red_Hat_Enterprise_Linux/6/html/Deployment_Guide/ch-Automating_System_Tasks.html#s2-configuring-cron-jobs

我有service crond startchkconfig crond on。然后我编辑 /etc/crontab 并添加:

*/5 * * * * my-user /path/to/shell.sh

我做了一个chmod +x shell.sh。我确保在最后添加一个换行符。

我希望它每 5 分钟运行一次,但它永远不会执行。

我做错了什么?

【问题讨论】:

  • CronJob not running的可能重复
  • 怎么发现它没有运行?它运行有几个定义。例如:整个 crontab 可能根本没有运行。或者由于语法错误,可能无法执行此特定的 cronjob。或者该文件没有正确的执行权限。或者文件本身包含错误。那么到目前为止你到底发现了什么?
  • 啊@Cfx 的帖子确实链接到了一个很好的答案

标签: crontab rhel


【解决方案1】:

只需尝试添加 cronjob 条目并通过获取脚本中的可查看输出来检查脚本是否正常工作。

echo "test time - $(date)" > script.sh
chmod +x script.sh
crontab -e

然后输入cronjob如下,

*/5 * * * * sh /path/to/script.sh > /path/to/log.file

检查日志是否正确写入。如果没问题,最好交叉检查您尝试通过 cron 执行的脚本。否则会是 cron 问题。

【讨论】:

    猜你喜欢
    • 2013-07-02
    • 1970-01-01
    • 2018-12-09
    • 2014-07-22
    • 2018-06-25
    • 2017-11-03
    • 1970-01-01
    相关资源
    最近更新 更多