Interview Prep/Shell Scripting/Troubleshooting: cron and systemd timers

A cron job fails intermittently, but there are no emails and no logs. Syslog shows `(CRON) info (No MTA installed, discarding output)`.

BeginnerTroubleshootingTroubleshooting: cron and systemd timers
Answer

Likely causes → cron mails a job's stdout/stderr to MAILTO (default: the crontab owner). With no mail transfer agent installed, the output, including every error message, is thrown away.

Diagnose →

grep CRON /var/log/syslog | tail      # job start lines plus "discarding output"
command -v sendmail || echo "no MTA"

Fix → Log explicitly instead of relying on mail:

MAILTO=""
*/5 * * * * /opt/opskit/bin/health.sh >> /var/log/opskit/health.log 2>&1

Or send output to the journal: ... 2>&1 | logger -t opskit-health. Note that cron now sees logger's exit status, not the script's, so the script must alert on its own failures.

Prevent → Each script writes its own logs and sends its own alerts on failure, so cron's mail is irrelevant. systemd timers solve this by capturing output in the journal by default.

All Shell Scripting questions Roadmap: Shell scripting (Bash)

More on Troubleshooting: cron and systemd timers