Site icon New Generation Enterprise Linux

Keep cron from mailing your local root account to death

Cron & Task Scheduling (Cron/Systemd Timers/At)

Keep cron from mailing your local root account to death

đź§© The Challenge

Dealing with a local mail spool that hit 10 gigabytes because your crontab script is constantly barfing warnings into stdout is a nightmare. I once spent an hour clearing out inode bloat just because a backup script had a silent typo.

đź’ˇ The Fix

Just redirect your crontab output to null or a specific log file so the system doesn’t try to send those local mail notifications. It keeps your disk clean and stops the annoying mail warnings.

* * * * * /usr/local/bin/backup.sh > /dev/null 2>&1

⚙️ Why It Works

Adding the redirect for both standard output and standard error tells the shell to throw away anything your script outputs rather than piping it to the local sendmail binary. Most people forget the 2>&1 part, which is how you end up with gigabytes of stderr logs filling up your partition.

🚀 Pro-Tip: If you need to see what’s happening, swap /dev/null for /var/log/cron-job.log and add a logrotate entry for it.

Linux Tips & Tricks | © ngelinux.com | 10/7/2026

0 0 votes
Article Rating
Exit mobile version