Logging output of cronjobs

If you wish to send output of cronjobs to syslog instead of email use the following:

20 10 * * * /opt/script/dostuff.py 2>&1 | /usr/bin/logger -t stuffdoer

If you want live-updates in the log file it can be necessary to unbuffer it, install the “expect” package and modify the command like so:

20 10 * * * /usr/bin/unbuffer /opt/script/dostuff.py 2>&1 | /usr/bin/logger -t stuffdoer

If it’s a python script you can accomplish the same thing by adding “-u” to the shebang.

Dette indlæg blev udgivet i Linux. Bogmærk permalinket.