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

时间:2015-04-24 09:26:37

标签: tomcat cron centos logrotate catalina

我创建了一个策略来旋转tomcat的catalina.out,我的cron服务正在运行,我甚至可以检查日志来验证作业但我没有得到所需的输出。这是我的代码

/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 /日志/ 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它就可以完成工作。

enter image description here

1 个答案:

答案 0 :(得分:0)

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

setenforce 0