Linux · Systems fluency
How does cron work and what are its pitfalls?
Short answer
cron runs commands on a schedule defined by five time fields: minute, hour, day of month, month, and day of week. Jobs run with a minimal environment and no terminal, which causes most cron failures.
Each user can have a crontab, and system-wide jobs can live in /etc/crontab or /etc/cron.d. The cron daemon checks schedules every minute and starts the command as the owning user. Job output is usually mailed or sent to syslog.
crontab -l
crontab -e
0 2 * * * /usr/local/bin/backup.sh >> /var/log/backup.log 2>&1The common failure modes
- PATH is minimal, so use absolute paths or set PATH explicitly
- There is no terminal, so interactive prompts hang indefinitely
- Overlapping runs can corrupt data unless you add a lock
- A percent sign in the command is special unless escaped
- Missed runs during downtime are not replayed by cron
For anything important, log stdout and stderr to a file or the journal and monitor job success. Consider systemd timers when you need dependency handling, persistent catch-up, or better status reporting.
Follow-ups you should expect
Interviewers use these to check whether the first answer was understanding or memorisation.
- 1Why does a script work manually but fail under cron?
- 2How do you prevent overlapping cron jobs?
- 3What happens to a job scheduled during downtime?
- 4When would you choose systemd timers over cron?
Say it in the interview
cron schedules commands with five time fields. The environment is minimal and there is no terminal, which explains most failures. I use absolute paths, set PATH explicitly, log output, and add locking to prevent overlap. For jobs that need catch-up or dependency handling, I prefer systemd timers.
Use this as a model, not a script. Saying it in your own words is what makes it survive follow-up pressure.
Related questions
Reading is step one
Now say it out loud.
Understanding an answer and delivering it under pressure are different skills. Rehearse this topic in a live Linux mock interview and get scored feedback on depth, clarity and confidence.