Cron 不打印到系统日志

Cron 不打印到系统日志

我有以下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 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 )

* * * * * mango echo hi >> /home/mango/test

我使用重新启动服务sudo service cron restart,但该文件没有出现。所以我检查了日志文件以查看问题。

Sep 18 09:24:41 dpiplserver rsyslogd: [origin software="rsyslogd" swVersion="5.8.6" x-pid="869" x-info="http://www.rsyslog.com"] rsyslogd was HUPed
Sep 18 09:24:51 dpiplserver anacron[1157]: Job `cron.daily' terminated
Sep 18 09:24:51 dpiplserver anacron[1157]: Normal exit (1 job run)
Sep 18 09:39:01 dpiplserver CRON[2349]: (root) CMD (  [ -x /usr/lib/php5/maxlifetime ] && [ -d /var/lib/php5 ] && find /var/lib/php5/ -depth -mindepth 1 -maxdepth 1 -type f -cmin +$(/usr/lib/php5/maxlifetime) ! -execdir fuser -s {} 2>/dev/null \; -delete)
Sep 18 10:09:01 dpiplserver CRON[2399]: (root) CMD (  [ -x /usr/lib/php5/maxlifetime ] && [ -d /var/lib/php5 ] && find /var/lib/php5/ -depth -mindepth 1 -maxdepth 1 -type f -cmin +$(/usr/lib/php5/maxlifetime) ! -execdir fuser -s {} 2>/dev/null \; -delete)
Sep 18 10:16:08 dpiplserver kernel: [ 4726.374034] usb 2-1.5: new high-speed USB device number 3 using ehci_hcd
Sep 18 10:39:01 dpiplserver CRON[2803]: (root) CMD (  [ -x /usr/lib/php5/maxlifetime ] && [ -d /var/lib/php5 ] && find /var/lib/php5/ -depth -mindepth 1 -maxdepth 1 -type f -cmin +$(/usr/lib/php5/maxlifetime) ! -execdir fuser -s {} 2>/dev/null \; -delete)
Sep 18 10:50:21 dpiplserver kernel: [ 6773.998690] init: cron main process (1192) killed by TERM signal
Sep 18 10:50:21 dpiplserver cron[2880]: (CRON) INFO (pidfile fd = 3)
Sep 18 10:50:21 dpiplserver cron[2881]: (CRON) STARTUP (fork ok)
Sep 18 10:50:21 dpiplserver cron[2881]: (*system*) INSECURE MODE (group/other writable) (/etc/crontab)
Sep 18 10:50:21 dpiplserver cron[2881]: (CRON) INFO (Skipping @reboot jobs -- not system startup)
Sep 18 10:52:17 dpiplserver kernel: [ 6890.091067] init: cron main process (2881) killed by TERM signal
Sep 18 10:52:17 dpiplserver cron[2905]: (CRON) INFO (pidfile fd = 3)
Sep 18 10:52:17 dpiplserver cron[2906]: (CRON) STARTUP (fork ok)
Sep 18 10:52:17 dpiplserver cron[2906]: (*system*) INSECURE MODE (group/other writable) (/etc/crontab)
Sep 18 10:52:17 dpiplserver cron[2906]: (CRON) INFO (Skipping @reboot jobs -- not system startup)
Sep 18 10:54:41 dpiplserver kernel: [ 7033.797057] init: cron main process (2906) killed by TERM signal
Sep 18 10:54:41 dpiplserver cron[2937]: (CRON) INFO (pidfile fd = 3)
Sep 18 10:54:41 dpiplserver cron[2938]: (CRON) STARTUP (fork ok)
Sep 18 10:54:41 dpiplserver cron[2938]: (*system*) INSECURE MODE (group/other writable) (/etc/crontab)
Sep 18 10:54:41 dpiplserver cron[2938]: (CRON) INFO (Skipping @reboot jobs -- not system startup)
Sep 18 10:56:01 dpiplserver cron[2938]: (*system*) INSECURE MODE (group/other writable) (/etc/crontab)
Sep 18 10:56:57 dpiplserver kernel: [ 7168.922614] init: cron main process (2938) killed by TERM signal
Sep 18 10:56:57 dpiplserver cron[2953]: (CRON) INFO (pidfile fd = 3)
Sep 18 10:56:57 dpiplserver cron[2954]: (CRON) STARTUP (fork ok)
Sep 18 10:56:57 dpiplserver cron[2954]: (*system*) INSECURE MODE (group/other writable) (/etc/crontab)
Sep 18 10:56:57 dpiplserver cron[2954]: (CRON) INFO (Skipping @reboot jobs -- not system startup)
Sep 18 10:59:34 dpiplserver kernel: [ 7325.393315] init: cron main process (2954) killed by TERM signal
Sep 18 10:59:34 dpiplserver cron[2967]: (CRON) INFO (pidfile fd = 3)
Sep 18 10:59:34 dpiplserver cron[2968]: (CRON) STARTUP (fork ok)
Sep 18 10:59:34 dpiplserver cron[2968]: (*system*) INSECURE MODE (group/other writable) (/etc/crontab)
Sep 18 10:59:34 dpiplserver cron[2968]: (CRON) INFO (Skipping @reboot jobs -- not system startup)
Sep 18 11:00:21 dpiplserver kernel: [ 7372.324581] init: cron main process (2968) killed by TERM signal
Sep 18 11:00:21 dpiplserver cron[2977]: (CRON) INFO (pidfile fd = 3)
Sep 18 11:00:21 dpiplserver cron[2978]: (CRON) STARTUP (fork ok)
Sep 18 11:00:21 dpiplserver cron[2978]: (*system*) INSECURE MODE (group/other writable) (/etc/crontab)
Sep 18 11:00:21 dpiplserver cron[2978]: (CRON) INFO (Skipping @reboot jobs -- not system startup)
Sep 18 11:09:01 dpiplserver CRON[3060]: (root) CMD (  [ -x /usr/lib/php5/maxlifetime ] && [ -d /var/lib/php5 ] && find /var/lib/php5/ -depth -mindepth 1 -maxdepth 1 -type f -cmin +$(/usr/lib/php5/maxlifetime) ! -execdir fuser -s {} 2>/dev/null \; -delete)
Sep 18 11:09:18 dpiplserver crontab[3068]: (mango) LIST (mango)
Sep 18 11:09:50 dpiplserver crontab[3089]: (root) LIST (root)
Sep 18 11:13:34 dpiplserver kernel: [ 8163.398965] init: cron main process (2978) killed by TERM signal
Sep 18 11:13:34 dpiplserver cron[3144]: (CRON) INFO (pidfile fd = 3)
Sep 18 11:13:34 dpiplserver cron[3145]: (CRON) STARTUP (fork ok)
Sep 18 11:13:34 dpiplserver cron[3145]: (*system*) INSECURE MODE (group/other writable) (/etc/crontab)
Sep 18 11:13:34 dpiplserver cron[3145]: (CRON) INFO (Skipping @reboot jobs -- not system startup)
Sep 18 11:15:22 dpiplserver kernel: [ 8271.390434] init: cron main process (3145) killed by TERM signal
Sep 18 11:15:22 dpiplserver cron[3163]: (CRON) INFO (pidfile fd = 3)
Sep 18 11:15:22 dpiplserver cron[3164]: (CRON) STARTUP (fork ok)
Sep 18 11:15:22 dpiplserver cron[3164]: (*system*) INSECURE MODE (group/other writable) (/etc/crontab)
Sep 18 11:15:22 dpiplserver cron[3164]: (CRON) INFO (Skipping @reboot jobs -- not system startup)

我期望日志文件会显示它运行的命令或它遇到的错误。为什么它既不打印成功也不打印错误?

答案1

请注意,该文件/etc/crontab具有错误的权限,这使得cron忽略该文件并且不运行该文件内的任务:

9 月 18 日 11:15:22 dpiplserver cron[3164]: (系统) 不安全模式(组/其他可写)(/etc/crontab)

使用命令修复它

sudo chmod 600 /etc/crontab

并重新启动服务

sudo service cron restart

相关内容