3

How can I execute logRotate daily at a specific time (3h30) each day? Specific details on how to do this would be appreciated.

I'm on Debian.

2

Step #1 - create script

You can create a file such as this:

$ sudo gedit /etc/cron.d/logrotate

And add these lines to this file:

#!/bin/bash

/usr/sbin/logrotate /etc/logrotate.conf
EXITVALUE=$?
if [ $EXITVALUE != 0 ]; then
    /usr/bin/logger -t logrotate "ALERT exited abnormally with [$EXITVALUE]"
fi
exit 0

Step #2 - add script to crontab file

Then create a crontab entry that runs this script at 3h30 each day. To do this 2nd step edit the file /etc/crontab:

$ sudo gedit /etc/crontab

And add this line:

# m h dom mon dow user  command
30 3 * * *  root    /etc/cron.d/logrotate

NOTE: You might need to omit the user in some situations, like this:

# m h dom mon dow   command
30 3 * * *      /etc/cron.d/logrotate

Step #3 - make script executable

Lastly make the logrotate shell script (/etc/cron.d/logrotate) executable:

$ sudo chmod +x /etc/cron.d/logrotate

References

  • 1
    Thanks a lot, I have set up the scripts and I am waiting to see if it works, hope so. – Abdelilah Benaou Oct 22 '13 at 15:36
  • I had to remove the root login in order to make it work. – Abdelilah Benaou Oct 22 '13 at 20:35
  • 1
    @AbdelilahBenaou - did you change it to something else or completely delete it? LMK so I can update the A. – slm Oct 22 '13 at 20:46
  • I changed the cron job line which goes like this : Before : 30 3 * * * root /etc/cron.d/logrotate After : 30 3 * * * /etc/cron.d/logrotate – Abdelilah Benaou Oct 23 '13 at 13:14
  • 1
    @AbdelilahBenaou - thanks I've added an example like this and a note. – slm Oct 23 '13 at 13:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.