正确设置后 Cron Job 未运行

正确设置后 Cron Job 未运行

因此我创建了一个 cron 作业,如下所示:

  GNU nano 2.2.6                    File: /tmp/crontab.uNoEXy/crontab

# Edit this file to introduce tasks to be run by cron.
#
# Each task to run has to be defined through a single line
# indicating with different fields when the task will be run
# and what command to run for the task
#
# To define the time you can provide concrete values for
# minute (m), hour (h), day of month (dom), month (mon),
# and day of week (dow) or use '*' in these fields (for 'any').#
# Notice that tasks will be started based on the cron's system
# daemon's notion of time and timezones.
#
# Output of the crontab jobs (including errors) is sent through
# email to the user the crontab file belongs to (unless redirected).
#
# For example, you can run a backup of all your user accounts
# at 5 a.m every week with:
# 0 5 * * 1 tar -zcf /var/backups/home.tgz /home/
#
# For more information see the manual pages of crontab(5) and cron(8)
#
# m h  dom mon dow   command
*/3 *  *    *   *    /home/kyle/runBackup.sh

测试一下 - 每三分钟按照指示运行一次脚本。是的,检查一下var/log/syslog- 今天没有 cron 运行。这个 cron 运行的证据是.tar.gz我的 dropbox 文件夹中的一个文件 - 如果你自己运行脚本,就会发生这种情况。只有将其放入 cron 中才会发生任何事情。

答案1

尝试:

*/3 * * * * /home/kyle/runBackup.sh

CRON 表达式是一个由五个或六个字段由空格分隔

有关详细信息,请参阅:http://en.wikipedia.org/wiki/Cron

答案2

我遇到过类似的问题,发现在计划运行作业后,邮件被放置在 root 的 /var/spool/mail 中,这是放置作业的 root crontab,表示 root 用户无权运行该作业。查看了一下,发现这是由于目标脚本不可执行。如果您这样做:

ls -la /home/kyle/

并且 runBackup.sh 显示 -rw-r--r-- 权限然后尝试:

chmod +x /home/kyle/runBackup.sh

这应该产生权限 -rwxr-xr-x 并允许作业运行。

源材料

相关内容