Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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)

btw- i'm using debian

My questions is- Is there any way I can tell cron not write this information to syslog every time?

share|improve this question
    
Any idea how to do this on a Busybox platform? The format of /etc/syslog.conf is different... –  Mark Lakata May 15 '13 at 0:14

5 Answers 5

You can send the output of cron to a separate log facility add the following to your /etc/syslog.conf file:

# Log cron stuff
cron.*                                                  /var/log/cron

Remember to add /var/log/cron to your /etc/logrotate.d/syslog to ensure it gets rotated, eg

# /etc/logrotate.d/syslog
/var/log/messages /var/log/secure /var/log/maillog /var/log/spooler /var/log/boot.log /var/log/cron {
    sharedscripts
    postrotate
    /bin/kill -HUP `cat /var/run/syslogd.pid 2> /dev/null` 2> /dev/null || true
    endscript
}
share|improve this answer
    
Thank you for the input. I added cron.* /var/log/cron and restarted cron but it continues to dump the messages into /var/log/syslog while leaving /var/log/cron empty. not sure why it's not doing anything –  user7321 Jun 25 '09 at 3:49
    
oh man, epic failure on my part. I was editing syslog.conf and restarting cron!! No wonder it wouldn't work.. I should have been restarting syslog =) –  user7321 Jun 25 '09 at 3:56
up vote 7 down vote accepted

Ok,

The solution to my question was:

change

*.*;auth,authpriv.none     -/var/log/syslog

to

*.*;cron,auth,authpriv.none     -/var/log/syslog

within /etc/syslog.conf and then restart syslog

I 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:

  1. it keeps /var/log/syslog from being cluttered with cron messages
  2. I still get cron messages (which is nice for troubleshooting)
  3. logrotate keeps /var/log/cron.log from going too large.
share|improve this answer

Change /etc/default/cron

  # Or, to log standard messages, plus jobs with exit status != 0:
  # EXTRA_OPTS='-L 5' 
  #
  # For quick reference, the currently available log levels are:
  #   0   no logging (errors are logged regardless)
  #   1   log start of jobs
  #   2   log end of jobs
  #   4   log jobs with exit status != 0
  #   8   log the process identifier of child process (in all logs)
  #
  EXTRA_OPTS="-L 0"

By default the EXTRA_OPTS line is ""

share|improve this answer

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:

  1. Preventing syslogd from appending cron-related log messages to /var/log/syslog
  2. Ensuring cron log messages do get logged somewhere (specifically, in /var/log/cron) + ensuring log rotation for the cron log.
  3. Preventing syslogd from appending cron-related log messages to /var/log/messages as well

In your /etc/syslog.conf, the combination of these changes something like

*.*;cron,auth,authpriv.none                         -/var/log/syslog
auth,authpriv.none;daemon.none;mail,news.none       -/var/log/messages

to

cron.*                                              /var/log/cron.log
*.*;cron,auth,authpriv.none                         -/var/log/syslog
auth,authpriv.none;cron,daemon.none;mail,news.none  -/var/log/messages

And don't forget to force-reload (or restart) both the cron and syslogd services, e.g. using:

/etc/init.d/syslogd force-reload
/etc/init.d/cron force-reload

Note: This works with rsyslog.d as well, and probably also with syslog-ng (possibly with some minor tweaking for syntax).

share|improve this answer

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:

cron.*              | grep -v "(/usr/libexec/atrun)" >> /var/log/cron.log

I haven't investigated but I believe it should be possible to send those log entries to another target if they're still wanted.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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