Log CRON to syslog on Ubuntu

I got this message in by logs

No MTA installed, discarding output

This is because CRON (crontab) is sending it’s data to a mail client. Ubuntu does not come with a mail client, so it throws this error. But I don’t want mail for error logging, so I looked online and found that you can use logger and pipe your CRON command to it.

I use a date function, so make sure to escape the %’s.

02 4 * * * (/usr/bin/pg_dump your_database -U your_user -Fc > "/your/backup/folder/$(date '+\%Y-\%m-\%d').sql") 2>&1 | /usr/bin/logger -t BACKUP

So after is has been run you can find the relevant log messages.

sudo grep BACKUP /var/log/syslog

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

Get my next post right in your inbox via Blogsend
(I don't get your email address so I can't spam you)

Like this post? Follow @adriaanvrossum on Twitter