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

You copied a line from `crontab -e` into `/etc/cron.d/backup`, and syslog shows `Error: bad username; while reading /etc/cron.d/backup`. Meanwhile a teammate's user crontab mails `/bin/sh: 1: root: not found` every night.

BeginnerTroubleshootingTroubleshooting: cron and systemd timers
Answer

Likely causes → The two crontab formats differ by one field. Files in /etc/crontab and /etc/cron.d/ have a user column after the five time fields; user crontabs (crontab -e) do not. Your copied line has no user, so cron reads the command path as a username. Your teammate did the reverse, so cron runs root as a command.

Diagnose →

cat /etc/cron.d/backup
crontab -l -u alice | grep -n root

Fix →

# /etc/cron.d/backup  (system format: user field required)
30 2 * * * opskit /opt/opskit/bin/backup.sh
# crontab -e  (user format: no user field)
30 2 * * * /opt/opskit/bin/backup.sh

Prevent → Put a header comment with the field layout at the top of every system cron file, and prefer /etc/cron.d files from config management over hand-edited user crontabs.

All Shell Scripting questions Roadmap: Shell scripting (Bash)

More on Troubleshooting: cron and systemd timers