brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: MAILTO="" in a crontab stops cron from mailing every job's output

Cron
~/tips/tip-cron-mailto-empty-string

MAILTO=""

Turns off or redirects the mail cron sends with the output of each job.

On a server nobody reads local mail on, cron job output ends up in /var/mail or bounces around.

MAILTO=""
0 4 * * * /usr/local/bin/cleanup.sh
[email protected]
30 4 * * * /usr/local/bin/important.sh

By default cron mails any output of a job to the owner of the crontab. MAILTO="" switches mail off for the lines below it, and [email protected] sends the mail somewhere you do read. Assignments can be repeated, so quiet jobs and jobs that must report can sit in the same file. Mail only goes out when an MTA such as postfix or msmtp is installed. A log redirect with >> file 2>&1 is the better choice for jobs whose output you want to keep.

Further reading: crontab(5) manual page

Going deeper: Guide: find out why a Linux service failed, with journalctl

More Cron tips echo 'systemctl restart myapp' | at 03:00 tomorrow 55 23 28-31 * * [ "$(date -d tomorrow +\%d)" = 01 ] && /usr/local/bin/month-end.sh EDITOR=nano crontab -e 30 6 * * mon /usr/local/bin/weekly-report.sh @daily /usr/local/bin/backup.sh All Cron tips (32) All topics

Link