cron tutorial 2 logging

We have seen in our first part of cron tutorial how to schedule a particular job at a specified time. In this part, we will see how we can perform cron logging

By default the cron jobs are logged in /var/log/syslog file




If you want the cron logs to store it in a separate log file ( /var/log/cron.log) . Uncomment the line that starts with #cron*. /etc/rsyslog.d/50-default.conf



If there is no such file present in /etc/rsyslog.d, create 50-default.conf file and add the following entry

cron*.    /var/log/cron.log

Restart rsyslog by running the following command : sudo service rsyslog restart

Now all the cron logs will be stored in the /var/log/cron.log file

You can also redirect the output of individual cronjobs to their own log files .

*/1 * * * * root /home/jamal/test.sh >> /var/log/test.log

If you want to log both standard output as well as errors then use the following syntax

*/1 * * * * root /home/jamal/test.sh >> /var/log/test.log 2>&1

Logging Levels of cron:

man page of cron specifies the various Log levels:

1 : will log the start of all cron jobs
2:  will log the end of all cron jobs
4: will log all the failed jobs
8: will log the process number of all cron jobs

Open /etc/init/cron.conf and replace "exec cron" with "exec cron -L 8"

If there is no such file then you can edit /etc/init.d/cron and add the following line:

EXTRA_OPTS="-L 8" in the parameter section


Comments

Popular posts from this blog

bb.utils.contains yocto

Difference between RDEPENDS and DEPENDS in Yocto

make config vs oldconfig vs defconfig vs menuconfig vs savedefconfig