So, you might be receiving emails from your cronjobs every time they run… And perhaps all they do, is output a success message, or a log you don’t need.
You really only want to be notified if something goes wrong, right?
The easiest way would be, to edit your cronjob line, and add:
This way, normal messages go into limbo, but error messages would still be emailed to you.
But what if you want the thing to go completely silent?
Simply do the MAILTO trick! You can specify a MAILTO variable in crontab, which specifies where to send the emails to. If you make this variable empty, it won’t send any emails.
MAILTO="" # m h dom mon dow command @weekly /myjob1.sh @weekly /myjob2.sh @weekly /myjob3.sh
So, as you can see, we have three weekly jobs, but we only have to specify MAILTO once, and it will apply to all jobs in that crontab! (:
But you still want to know if things are up/down?
Of course, a good sysadmin wants to know if things are up or down… So, monitoring is important… But pesky emails are not what you want…
Use a monitoring service! There are a few services out there, where you can simply ping the service whenever a cronjob runs, and pings on error/success after the run.
This way, you can keep an eye on things, and see if things are running without constant emails. Of course, these monitoring services can notify you if a job fails, which makes sense.
I, personally, use healthchecks.io because it’s free for up to 20 jobs, which is perfect for an individual like me. The site healthchecks.io is run by one guy, it seems, and not a huge corporation, so if you can afford it, you should probably go for a paid plan. (:
Speaking of affording it, feel free to donate a cup of coffee so that I can write more articles like these! :D