cron 服务是 运行 但没有在 centos 中执行 cron 作业

cron service is running but not executing cron jobs in centos

我已经制定了轮换 catalina.out of tomcat 的策略,我的 cron 服务是 运行ning,我什至可以检查日志来验证作业,但我没有得到所需的输出。这是我的代码

/etc/logrotate.d/tomcat

/opt/tomcat7/logs/catalina.out {
    copytruncate
    rotate 7
    compress
    missingok
    size 1k
 }

/etc/crontab

SHELL=/bin/bash
PATH=/sbin:/bin:/usr/sbin:/usr/bin
MAILTO=root
HOME=/

# For details see man 4 crontabs

# Example of job definition:
# .---------------- minute (0 - 59)
# |  .------------- hour (0 - 23)
# |  |  .---------- day of month (1 - 31)
# |  |  |  .------- month (1 - 12) OR jan,feb,mar,apr ...
# |  |  |  |  .---- day of week (0 - 6) (Sunday=0 or 7) OR sun,mon,tue,wed,thu,fri,sat
# |  |  |  |  |
# *  *  *  *  * user-name command to be executed
  01 * * * * root run-parts /etc/cron.hourly
  02 4 * * * root run-parts /etc/cron.daily
  22 4 * * 0 root run-parts /etc/cron.weekly
  42 4 1 * * root run-parts /etc/cron.monthly
  * * * * * root /usr/sbin/logrotate -v /etc/logrotate.conf
  * * * * * root env > /opt/env.output

/var/log/cron

Apr 24 14:49:01 staging2 CROND[30862]: (root) MAIL (mailed 5331 bytes of output but got status 0x004b#012)
Apr 24 14:50:01 staging2 CROND[30903]: (root) CMD (/usr/lib64/sa/sa1 1 1)
Apr 24 14:50:01 staging2 CROND[30902]: (root) CMD (/usr/sbin/logrotate -v /etc/logrotate.conf)
Apr 24 14:50:01 staging2 CROND[30901]: (root) CMD (env > /opt/env.output)
Apr 24 14:50:01 staging2 CROND[30893]: (root) MAIL (mailed 5376 bytes of output but got status 0x004b#012)
Apr 24 14:51:01 staging2 CROND[30938]: (root) CMD (/usr/sbin/logrotate -v /etc/logrotate.conf)
Apr 24 14:51:01 staging2 CROND[30937]: (root) CMD (env > /opt/env.output)
Apr 24 14:51:01 staging2 CROND[30932]: (root) MAIL (mailed 5331 bytes of output but got status 0x004b#012)
Apr 24 14:52:01 staging2 CROND[30975]: (root) CMD (/usr/sbin/logrotate -v /etc/logrotate.conf)
Apr 24 14:52:01 staging2 CROND[30976]: (root) CMD (env > /opt/env.output)
Apr 24 14:52:01 staging2 CROND[30970]: (root) MAIL (mailed 5331 bytes of output but got status 0x004b#012)

我可以清楚地看到作业每分钟执行一次,它应该轮换 catalina 文件,但它没有这样做,如果我 运行 命令 /usr/sbin/logrotate -v /etc/logrotate.conf 手动完成作业。

我得到了解决方案。一切都很好,但你需要禁用 SELinux

setenforce 0