I'm trying to make httpry logs every 2 hours. I added this to my logrotate.conf file:

/var/log/httpry/*.log {
    rotate 1
    create 640 root admin

I tried changing weekly to hourly (still need every 2 hours), but it doesn't work. I read to copy a script from cron.daily to cron.hourly but all my cron files are empty.

How can I create a new log file every 2 hours?


I've seen this trick used before on a separate blog:

Create a config file for logrotate, let us call it httpry.conf

/var/log/httpry/*.log {
    size 2
    rotate 84

Then from cron (may need to be in root's crontab depending on the permissions and ownership of the log files), a crontab of:

0 */2 * * * logrotate -f /path/to/httpry.conf

EDIT: to describe crontab editing for OP

A crontab can be created for your user account by issuing crontab -e. If you want to edit a specific user's crontab, as root: crontab -e user or on some systems crontab -e -u user. You will then be put into an EDITOR which will allow you to edit the crontab, and wrting the file out will check the crontab for errors (giving an error if incorrect) or installing the crontab if correct.

The rotate 84 option, as he describes in the blog, is to keep a weeks worth of logs. (24/2 hour intervals = 12 logs per day, 12 * 7 = 84 .. or 1 weeks worth of logs).

| improve this answer | |
  • Can you explain the second part: 0 */2 * * * logrotate -f /etc/logrotate.d/apache? I have never worked with cron before so it's a little confusing. I don't have an apache folder in /etc/logrotate.d/ either. – o.o Aug 4 '15 at 19:19
  • Sorry that's a cut from my notes I took from the original blog, I will update to make clearer. – Drav Sloan Aug 4 '15 at 19:20
  • Just to clarify that crontab says "every two hours run the command logrotate -f /path/to/httpry.conf, more details can be found about crontab in the man pages man 1 crontab and man 5 crontab. – Drav Sloan Aug 4 '15 at 19:28
  • Sorry, computer won't boot up for some reason. Just to make sure, after I type crontab -e, I pasted the line 0 */2 **.... then saved it. I put httpry.conf in /etc/. – o.o Aug 4 '15 at 20:38
  • Never mind, I figured out why I couldn't boot. Thanks for all the help! – o.o Aug 4 '15 at 21:33

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.