I have a script which needs to be executed each minute. The problem is that cron is logging to /var/log/syslog
each time it executes. I end up seeing something like this repeated over and over in /var/log/syslog
:
Jun 25 00:56:01 myhostname /USR/SBIN/CRON[1144]: (root) CMD (php /path/to/script.php > /dev/null)
I'm using Debian.
My questions is: Is there any way I can tell cron not write this information to syslog every time?
You can send the output of cron to a separate log facility add the following to your
/etc/syslog.conf
file:Remember to add
/var/log/cron
to your/etc/logrotate.d/syslog
to ensure it gets rotated, egChange /etc/default/cron
By default the EXTRA_OPTS line is ""
Ok,
The solution to my question was:
change
to
within
/etc/syslog.conf
and then restart syslogI also have cron being sent to
/var/log/cron.log
as suggested by Dave Cheney and stuck a logrotate on it. My fix with Daves suggestion is optimal for my situation because:/var/log/syslog
from being cluttered with cron messages/var/log/cron.log
from going too large.In Ubuntu 14.04.5 (and likely elsewhere) there is rsyslogd instead of syslogd. TranslucentCloud hinted at this with Debian Jessie, but the same solution (but changing rsyslog.conf instead of syslogd.conf) doesn't appear to work in Ubuntu.
It appears that values set in /etc/rsyslog.d/50-default.conf will actually take precedence over stuff set in /etc/rsyslog.conf, so it's better to make the changes there and then restart rsyslog and cron. Otherwise you'll still end up with the default behavior of cron logging to syslog, plus cron logging to cronlog (but not exclusively).
First couple of lines in my /etc/rsyslog.d/50-default.conf:
And voila!
Actually, the 'best' (one could claim) solution is a combination of what @DaveCheney suggested and what user7321 did eventually, plus a third action which I would recommend:
In your
/etc/syslog.conf
, the combination of these suggestions changes something like the following:into:
And don't forget to force-reload (or restart) both the cron and syslogd services, e.g. using:
Note: This works with rsyslogd as well.
I just solved this in a different way, but my aim was slightly different. I wanted to discard the cron log entries that were generated when atrun fired so that my hard drives could sleep and not be woken every 5 minutes.
You can have the target of a log event in syslog.conf be a shell command by prefixing it with the pipe, and so I used grep to throw away the ones I didn't want. So:
I haven't investigated but I believe it should be possible to send those log entries to another target if they're still wanted.