Cron 任务偶尔运行

Cron 任务偶尔运行

我有一台计算机,它似乎有时会运行 cron 作业。当我监控系统日志时,我可以看到提到的作业,但看不到命令​​的结果。我该如何解决这个问题?

此盒子的版本:

username:/etc$ uname -rvp
4.13.0-32-generic #35~16.04.1-Ubuntu SMP Thu Jan 25 10:13:25 UTC 2018 i686

文件/etc/crontab内容(附有我的注释):

username:/etc$ cat /etc/crontab
# /etc/crontab: system-wide crontab
# Unlike any other crontab you don't have to run the `crontab'
# command to install the new version when you edit this file
# and files in /etc/cron.d. These files also have username fields,
# that none of the other crontabs do.

SHELL=/bin/sh
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin

# m   = minute
# h   = hour (24-hour)
# dom = day of month
# mon = month (numeric)
# dow = day of week (sunday is 0, monday is 1, saturday is 6)
# user    = user
# command = yep
# *       = blank or null entry or wildcard

# m h dom mon dow user  command
17 *    * * *   root    cd / && run-parts --report /etc/cron.hourly
#25 6   * * *   root    test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.daily )
#47 6   * * 7   root    test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.weekly )
#52 6   1 * *   root    test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.monthly )
01 18   * * 1   root    /sbin/shutdown -h now
00 20   * * 1   root    /sbin/shutdown -h now
01 18   * * 2   root    /sbin/shutdown -h now
00 20   * * 2   root    /sbin/shutdown -h now
01 18   * * 3   root    /sbin/shutdown -h now
00 20   * * 3   root    /sbin/shutdown -h now
01 18   * * 4   root    /sbin/shutdown -h now
00 20   * * 4   root    /sbin/shutdown -h now
01 18   * * 5   root    /sbin/shutdown -h now
00 20   * * 5   root    /sbin/shutdown -h now
01 16   * * 6   root    /sbin/shutdown -h now
00 20   * * 6   root    /sbin/shutdown -h now
## This is a test entry.
45 10   * * *   root    /usr/bin/notify-send 'Cronjob Test Message' 'This is a cronjob test message.'
46 10   * * 1   root    /usr/bin/notify-send 'Cronjob Monday Test Message' ' This is Mondays cronjob test message.'
20 11   * * *   root    /usr/bin/notify-send 'Test' 'Message goes here.'
#51 11   * * 4   root    shutdown -h now
# This line is the last line, be sure to terminated this line with a new line.

请注意,我正在进行各种测试。我意识到这很令人困惑,所以我将简化文件/etc/crontab以便于故障排除。这是我的新/etc/crontab故障排除文件:

username:/etc$ cat /etc/crontab
# /etc/crontab: system-wide crontab
# Unlike any other crontab you don't have to run the `crontab'
# command to install the new version when you edit this file
# and files in /etc/cron.d. These files also have username fields,
# that none of the other crontabs do.

SHELL=/bin/sh
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin

56 11   * * *   root    /usr/bin/notify-send 'Test' 'Message goes here.'

现在,我查看我的系统日志:

username:/etc$ /usr/bin/sudo /usr/bin/tail /var/log/syslog -f
Jan 29 10:58:31 hostname dbus[730]: [system] Successfully activated service 'org.freedesktop.timedate1'
Jan 29 10:58:31 hostname systemd[1]: Started Time & Date Service.
Jan 29 11:10:01 hostname cron[759]: (*system*) RELOAD (/etc/crontab)
Jan 29 11:10:01 hostname CRON[3240]: (root) CMD (/usr/bin/notify-send 'Test' 'Message goes here.')
Jan 29 11:17:01 hostname CRON[3283]: (root) CMD (   cd / && run-parts --report /etc/cron.hourly)
Jan 29 11:19:01 hostname cron[759]: (*system*) RELOAD (/etc/crontab)
Jan 29 11:20:01 hostname CRON[3314]: (root) CMD (/usr/bin/notify-send 'Test' 'Message goes here.')
Jan 29 11:34:35 hostname crontab[3386]: (root) BEGIN EDIT (root)
Jan 29 11:35:46 hostname crontab[3386]: (root) END EDIT (root)
Jan 29 11:55:01 hostname cron[759]: (*system*) RELOAD (/etc/crontab)
Jan 29 11:56:01 hostname cron[759]: (*system*) RELOAD (/etc/crontab)
Jan 29 11:56:01 hostname CRON[3537]: (root) CMD (/usr/bin/notify-send 'Test' 'Message goes here.')

最后一行说在 11:56:01 运行了命令/usr/bin/notify-send但没有显示弹出消息。

如果我从终端运行该精确(复制和粘贴)命令,/usr/bin/sudo则会出现弹出窗口。

username:/etc$ /usr/bin/sudo /usr/bin/notify-send 'Test' 'Message goes here.'

如果我以普通用户登录的身份从终端运行该精确(复制和粘贴)命令,则会出现弹出窗口。

username:/etc$ /usr/bin/notify-send 'Test' 'Message goes here.'

是什么赋予了?

相关内容