-1

I have a cron task configured in cron.d directory that would get executed for every 5 minutes. The entry is

*/5  *  *  *  *   root   /usr/sbin/logrotate /etc/logrotate.d/test_consolelog

This would invoke the logrotate. However the logrotate didn't happen. I checked the /var/log/cron file to see if cron executes the command and could see that the command is getting executed for every 5 minutes.

I tried executing the command mannually on the terminal and could see that the command is executed and log rotation happens.

What could be reason that logrotate is not happening when getting executed from cron.d.

Regars, Bala

Balachandar
  • 1,538
  • 3
  • 16
  • 25
  • That may depend on test_consolelog logrotate configuration (like it does not rotate becuase you just tried manually and no condition triggers the rotation), pls add it to the question; or, if you want to always force logrotate to run even if conditions are not met, use option `-f` – guido May 18 '15 at 05:02
  • Sorry to miss it. I have configured the logrotate to rotate when ever the size of the file exceeds 20Mb. When the cron task executes i checked the size of file to be more than 35 Mb. Still the logrotation failed. When i trigger the same manually, rotation was successfull. The entry in logrotate config file is /var/test/testagent/logs/*.log { nocompress copytruncate notifempty missingok rotate 50 size 20M } – Balachandar May 18 '15 at 05:04
  • What do you mean by "failed"? Did you get any error, or just did not happen? Anyway, try changing the cron command to `*/5 * * * * root /usr/sbin/logrotate -f /etc/logrotate.d/test_consolelog` and see what happens – guido May 18 '15 at 05:06
  • The main problem here is i didn't find any errors :(. Just it did not happen. Anyway i am trying -f option. – Balachandar May 18 '15 at 05:09
  • Failed now too. How ever in /var/log/cron i could see the error msg "(CRON) bad minute (/etc/cron.d/logrotate)" – Balachandar May 18 '15 at 05:11
  • 1
    Then that is the error, isn't it? – tripleee May 18 '15 at 05:52
  • */5 * * * * root /usr/sbin/logrotate /etc/logrotate.d/test_consolelog is the entry in /etc/cron.d/logrotate file. Would be helpful if the error is pointed out.. – Balachandar May 18 '15 at 06:12
  • Looks like you have a primitive cron which doesn't recognize the slash notation. Try with writing it out in longhand 0,5,10,15,20,25,30,35,40,45,50,55 – tripleee May 18 '15 at 06:57
  • Tried 5 instead of */5 and failed in that too – Balachandar May 18 '15 at 10:17
  • I suspect it is problem with my logrotate.. I am investigating in that direction – Balachandar May 18 '15 at 10:23

1 Answers1

0

I found the root cause. The SELinux needs to be disabled for this to work. Earlier while testing the sestatus value is disabled in the the /etc/selinux/config file however the current status was enforcing. Once i restarted the vm itself the sestatus updated to disabled and logrotate functioned as desired. prior to that i have fixed the bad minute error too.

I had furnished enough details for this post and done enough research before posting here. However i am not sure why some one marked this post as there is no research effort or unclear or unuseful...

Balachandar
  • 1,538
  • 3
  • 16
  • 25