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

A new job in `/etc/cron.d/opskit` never runs. Syslog shows `cron[812]: (*system*opskit) ERROR (Missing newline before EOF, this crontab file will be ignored)`.

BeginnerTroubleshootingTroubleshooting: cron and systemd timers
Answer

Likely causes → cron requires every line, including the last, to end with a newline. The file was generated with printf without \n, or by a config-management template that stripped the final newline, so cron ignores the whole file.

Diagnose →

tail -c 1 /etc/cron.d/opskit | od -c        # last byte is not \n
grep -i 'cron.*opskit' /var/log/syslog       # or: journalctl -u cron --since today

Fix → Append the newline; cron rereads /etc/cron.d automatically on its next minute check:

printf '\n' >> /etc/cron.d/opskit

Also confirm the file is owned by root, mode 0644, and not group/world writable, or cron ignores it for security (WRONG FILE OWNER / BAD FILE MODE).

Prevent → Ship cron files through config management with an explicit trailing newline and a validation step, or move the job to a systemd timer.

All Shell Scripting questions Roadmap: Shell scripting (Bash)

More on Troubleshooting: cron and systemd timers