11

I have this directive on my crontab:

* * * * * /var/www/github/mysite/bin/email email worker await --pid=/var/run/mysite-worker-email.pid >> /tmp/mysite-worker-email.log

As you can see all my logs are written in /tmp/mysite-worker-email.log, is there a way I can rotate that file?

2
  • @Sven My system is not doing any logrotate, im just dumping the echo of a php script on a file using crontab: * * * * * myscript >> log.txt
    – DomingoSL
    Jul 6, 2015 at 12:29
  • @DomingoSL the point is, the machine on which you are running your crontab entry probably does have logrotate installed. You can use logrotate to rotate any logs, including your own, and it's probably the most standard solution. Are you the sysadmin for this machine or is it shared hosting or something? Jul 6, 2015 at 12:43

1 Answer 1

23

Assuming you have root permissions on the machine. If you are on shared hosting, SF is the wrong site for you anyway.

Check if /etc/logrotate.conf and /etc/logrotate.d exists. If they do, add a file with a fitting name, e.g. site_email into /etc/logrotate.d with a content like the following:

/tmp/mysite-worker-email.log {
   compress
   daily 
   missingok
   rotate 7
}

This will rotate the log files daily, and keep compressed copies of the last 7 days. logrotate has many more options, see man logrotate.conf for all of them.

Please note: Keeping log files in /tmp is a bad idea. Put them into /var/log/ where they belong, especially if you want to keep more copies of the log file and don't want them to get deleted when /tmp is cleaned up.

You must log in to answer this question.

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