User avatar
bonzadog
Posts: 274
Joined: Wed Apr 25, 2012 9:40 am
Location: Rietberg/Germany

where is the log for crontab? not syslog

Sun Jun 25, 2017 9:09 am

26.6.2017
Can someone please help me?

Yesterday I had problems with @reboot in crontab and after a lot of hunting I found someone who
could display the crontab log, showing that @reboot was starting up
and which shell was started. This log was specific for crontab and not the syslog.
This help me to solve the problem.
In spite of searching again for that help I just cannot find it.

I did try
sudo grep -r "@reboot" /
that should show all files containing "@reboot" but this stops after
displaying grep: /sys/kernel/slab/kmem_cache_node/free_calls: Function not implemented.
But does show the syslog entries


Thank you.

pcmanbob
Posts: 11946
Joined: Fri May 31, 2013 9:28 pm
Location: Mansfield UK

Re: where is the log for crontab? not syslog

Sun Jun 25, 2017 12:13 pm

Hi.
From what I can see cron ( crontab is just the corn editor ) does not have logging turned on, so does not produce log entries.( to save writing to SD card un-necessarily )
to turn cron logging on your need to edit : /etc/rsyslog.conf

Code: Select all

 sudo nano /etc/rsyslog.conf
and look for the section Rules and uncomment the line

Code: Select all

 # cron.*                          /var/log/cron.log
save the file and reboot your pi and cron logging should be on and logging to : /var/log/cron.log

another way to create logs form programs run using cron is to add >> /home/pi/my.log 2>&1 to the end of the line and all output will be written to the log file you specified.
example

Code: Select all

@reboot python /home/pi/somecode.py  >> /home/pi/my.log 2>&1
advantage being you can log each program to a different log and if you don't need a particular one any more you can just edit the cron line to remove it, so reducing writes to the SD card
We want information… information… information........................no information no help
The use of crystal balls & mind reading are not supported

User avatar
bonzadog
Posts: 274
Joined: Wed Apr 25, 2012 9:40 am
Location: Rietberg/Germany

Re: where is the log for crontab? not syslog

Sun Jun 25, 2017 12:15 pm

Thank you for your input but I definitely saw a log file without the cron.log being activated.

But I have now set the cron config to start the cron.log as you suggested, but it does not look like the log I had displayed.
I can remember hat some text was enclosed in [ ] - not exactly a huge help but perhaps it may help

I had deleted my history so I could not repeat the command.
Last edited by bonzadog on Sun Jun 25, 2017 12:48 pm, edited 2 times in total.

pcmanbob
Posts: 11946
Joined: Fri May 31, 2013 9:28 pm
Location: Mansfield UK

Re: where is the log for crontab? not syslog

Sun Jun 25, 2017 12:30 pm

bonzadog wrote:Thank you for your input but I definitely saw a log file.

unless you did one or the other of the above cron will not have produced a log file, as logging is off by default. may be the program you ran produced a log file and that's what you looked at.
only other references to cron are :
/var/log/syslog shows cron entries for programs run
/var/log/auth.log shows sessions open/closed for cron
We want information… information… information........................no information no help
The use of crystal balls & mind reading are not supported

User avatar
rpdom
Posts: 19283
Joined: Sun May 06, 2012 5:17 am
Location: Chelmsford, Essex, UK

Re: where is the log for crontab? not syslog

Sun Jun 25, 2017 2:06 pm

pcmanbob wrote:
bonzadog wrote:Thank you for your input but I definitely saw a log file.

unless you did one or the other of the above cron will not have produced a log file, as logging is off by default.
The default is for most message to be logged to /var/log/syslog. This includes cron unless you override it as you have suggested.

A better idea would be to look at /etc/default/cron, particularly where it says:

Code: Select all

# 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)
The default log level is 1: log start of jobs

Return to “Raspberry Pi OS”