0

A month ago I set cron to log to /var/log/cron.log by modifying /etc/rsyslog.d/50-default.conf. Logging worked great until I changed permissions on /var/log (by easing permission restrictions), and forced logrotate to rotate the logs by executing logrotate --force /etc/rsyslog.d/50-default.conf. Since then, cron seems to have stopped logging. There is no longer a /var/log/cron.log. I executed sudo touch /var/log/cron.log to create it, but it has remained 0 bytes since.

More details on what I did with the permissions:

I ran sudo chmod 775 /var/log, and subsequently changed permissions back with sudo chmod 755 /var/log. All other services appear to be logging correctly, and cron jobs are actually running (verified with ps aux | grep rsync, since I only run rsync via cron).

I wasn't sure of the correct user and group access rights for cron.log so I tried changing it to syslog:adm like most of the other log files, but that didn't help, so I switched it back to root:root,

Current permissions on cron.log: -rwxr-xr-x 1 root root 0 Apr 27 16:34 cron.log

Not sure where to go from here. I know I can have cron log to any file I'd like (either by adding >> /path/to/logfile to end of cron job entries or by editing /etc/rsyslog.d/50-default.conf), but for consistency, I would prefer it continue logging to cron.log. I suppose I could add >> /var/log/cron.log to the end of each cron entry, but that seems a little hacky to me.

EDIT: As per my comment below, I changed the log location to /tmp/cron.logand logging has resumed. At first, I had assumed this implied that either the folder or file permissions are wrong. However, I checked them against another machine running the same distro, and the folder permissions were correct. The file permissions were not restrictive enough, the correct permissions can be set with sudo chmod 640 cron.log.

As a test, I deleted the empty cron.log, and it was never recreated. I modified the rsyslogd config to have it log to crond.log, but the file was never created.

  • I just had the same problem, I uncommented the line in /etc/rsyslog.d/50-default.conf to enable logging into cron.log but the file wasn't created :( I then manually created it with a touch and it was always empty. I finally succeeded to make working by typing : sudo chmod 640 /var/log/cron.log && sudo chown syslog:adm /var/log/cron.log – Kervala Oct 28 '17 at 14:05
0

Why you didn't try to edit /etc/rsyslog.conf ?! As you know you can force rsyslog to log service that hasn't specific logger. So I suggest read man rsyslog.conf to know how make service making log and edit the service to send logs here ( edit somewhere like /etc/init.d/rsyslog to configure log section ).

  • I would like it to continue logging to /var/log/cron.log, though. However, you gave me an idea: for troubleshooting purposes, I'm going to change the destination in /etc/rsyslog.d/50-default.conf to something like /tmp/cron.log. If it begins logging again, that should indicates a permissions issue with either /var/log/ or the log file itself. – Andy Forceno Apr 28 '16 at 16:09
  • That's a good idea. I by myself for service I wrote use this function for logging. Hope it helps you ;) – Ali Ghasempour Apr 28 '16 at 16:14

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.