Interview Prep/Linux/Scheduling, automation and scripting

A cron job's output fills root's mailbox with thousands of messages. How do you handle cron output properly?

BeginnerScenarioScheduling, automation and scripting
Answer

Situation read → Cron mails any output; redirect deliberately.

What I'd do →

  1. Send normal output to a log and only errors to mail:
[email protected]
*/10 * * * * app /usr/local/bin/job.sh > /var/log/job.log 2>&1 || echo "job failed"
  1. Or log to syslog: job.sh 2>&1 | logger -t job.
  2. Clean the backlog: > /var/spool/mail/root.

Why → Silent success, loud failure is the right pattern.

Interview tip → Better still: report to a dead-man's switch (Healthchecks.io, Cronitor) so missed runs alert too.

All Linux questions Roadmap: Linux

More on Scheduling, automation and scripting