3

I have lograotate configured on CentOS 6. It works fine when I run it manually, but with CRON it doesn't work. Cron says in its logs: "All fine, I run you command" but nothing happens. Details:

cat /etc/logrotate.d/myproject

/var/opt/myproject/log/error.log {
    size=200M
    rotate 25
    missingok
    notifempty
    copytruncate
    nocreate
    nocompress
    nodateext
}

cat /etc/cron.d/1everymin

SHELL=/bin/bash
PATH=/sbin:/bin:/usr/sbin:/usr/bin
MAILTO=root
HOME=/
* * * * * root /etc/cron.min/logrotate

cat /etc/cron.min/logrotate

#!/bin/sh

#/usr/sbin/logrotate /etc/logrotate.conf >/dev/null 2>&1
/usr/sbin/logrotate -v /etc/logrotate.conf > /logrotate.log
EXITVALUE=$?
if [ $EXITVALUE != 0 ]; then
    /usr/bin/logger -t logrotate "ALERT exited abnormally with [$EXITVALUE]"
fi
exit 0

Every minute I see in /var/log/cron

Jan 16 21:40:01 localhost CROND[31541]: (root) CMD (/etc/cron.min/logrotate)
Jan 16 21:41:01 localhost CROND[31552]: (root) CMD (/etc/cron.min/logrotate)
Jan 16 21:42:01 localhost CROND[31561]: (root) CMD (/etc/cron.min/logrotate)
Jan 16 21:43:01 localhost CROND[31575]: (root) CMD (/etc/cron.min/logrotate)
Jan 16 21:44:01 localhost CROND[31587]: (root) CMD (/etc/cron.min/logrotate)

But log actually is not rotated: nothing happens, /logrotate.log is empty

If I execute /etc/cron.min/logrotate manually all working fine, /logrotate.log have information about log rotating

3
  • 1
    Has the /var/opt/myproject/log/error.log gotten to the required size of 200M?
    – ZaSter
    Jan 23, 2013 at 20:10
  • Yes, of course. It's manually filled up to 500 mb. Ok, I dont know why, but when I add the same cronjob via crontab -e under the root user it works fine
    – odiszapc
    Jan 24, 2013 at 6:12
  • 1
    What are you expecting? because it's really common for people to assume the logs will rotate every time logrotate is run. That's not what it'll do here.
    – hookenz
    Mar 10, 2015 at 2:57

2 Answers 2

1

If SELinux is enabled, cron will not be allowed to write into / To see if it is enabled, use:

getenforce

Try logging somewhere else temporarily such as /var/log/logrotate.log

Be sure to look for denies in /var/log/audit/auditd.log assuming that auditd is enabled.

0

I think size=200M is wrong, instead size 200M is correct as per log rotate man page in your conf file /etc/logrotate.d/myproject

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .