每小时cron作业未运行 [英] Hourly cron job did not run
问题描述
我用 crontab -e
打开了我的crontab文件。然后我将它添加到我的crontab:
I opened my crontab file with crontab -e
. Then I added this to my crontab:
SHELL=/bin/bash
@hourly /home/ec2-user/utilities/create-snapshots.sh
然后我保存了该文件。大约一个小时后,显示cron日志:
Then I saved the file. After about an hour, the cron logs displayed:
CROND[1876]: (ec2-user) CMD (/home/ec2-user/utilities/create-snapshots.sh)
CROND[1877]: (root) CMD (/usr/lib64/sa/sa1 -S DISK 1 1)
CROND[1892]: (root) CMD (run-parts /etc/cron.hourly)
run-parts(/etc/cron.hourly)[1892]: starting 0anacron
run-parts(/etc/cron.hourly)[1901]: finished 0anacron
但是我知道命令 / home / ec2 -user / utilities / create-snapshots.sh
实际上没有运行,因为它会创建我的数据库的快照,而它没有。运行命令 /home/ec2-user/utilities/create-snapshots.sh
可以直接在终端中运行。
However I know that the command /home/ec2-user/utilities/create-snapshots.sh
was not actually run because it would have created snapshots of my database, which it did not. Running the command /home/ec2-user/utilities/create-snapshots.sh
works if I run it directly in the terminal.
我如何让cron每小时运行那个命令?
How can I get cron to run that command hourly?
推荐答案
我的心理调试能力告诉我, code> create-shapshots.sh 脚本运行,但由于环境变量问题(可能 PATH
)。 Cron通常使用清理过的环境运行命令,其中的东西比通常在shell提示符下的东西要少。
My psychic debugging powers tell me that the create-shapshots.sh
script was run, but it failed because of an environment variable problem (possibly PATH
). Cron normally runs commands with a cleaned-out environment, with much less stuff than what you normally have at a shell prompt.
这篇关于每小时cron作业未运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!