Log output of your cronjobs to syslog in Ubuntu

When I setup crontab for a script I want to have all logging in syslog. This way I can see all live output of the script with a single command tail -n 100 -f /var/log/syslog.

If I have this crontab */10 * * * * /home/user/do-something.sh (crontab -l) I would see this in the logs:

Dec 29 12:00:00 server CRON[1011]: (user) CMD (/home/user/do-something.sh)
Dec 29 12:00:00 server CRON[1009]: (CRON) info (No MTA installed, discarding output

No MTA installed, discarding output is basically saying that it can’t log because there is no email client. Default logs of cronjobs are send to an email client. This is not something I want so I change my crontab crontab -e to this:

*/10 * * * * /home/user/do-something.sh 2>&1 | /usr/bin/logger -t CRON

Explanation

If you use the name CRON you can search your logs like this cat /var/log/syslog | grep CRON and you have all output of the /home/user/do-something.sh script.

Happy coding! – Found a mistake or a typo? Please submit a PR to my GitHub-repo.

Like this post? Follow @adriaandotcom on X