Why Does My Cron Job Run Twice?
Duplicate cron runs almost always have one of three causes: the same line exists in two places (your user crontab and root's, or a file in /etc/cron.d), the daylight-saving fall-back repeated the 01:00-01:59 window, or a slow job overlapped its next scheduled start. Find the duplicate source first, then add a lock so runs can never overlap.
Track down the duplicate
- List every crontab that could hold it:
crontab -l,sudo crontab -l, and files in/etc/cron.d/,/etc/crontab,/etc/cron.daily/. - Grep the system log to see how many times cron fired it:
grep CRON /var/log/syslog | grep myscript.
Common causes
- Two crontabs: the entry is in both the user and root crontab, or duplicated in
/etc/cron.d. Remove one. - DST fall-back: when clocks go back, jobs scheduled between 01:00-01:59 run twice. Schedule such jobs outside that window or use UTC.
- Overlap: a run that takes longer than its interval collides with the next start. Guard with a lock.
Prevent overlap with a lock
Wrap the command in flock so a second copy exits immediately:
* * * * * /usr/bin/flock -n /tmp/myjob.lock /path/to/script.sh
FAQ
Why does my cron job run twice at the same time?
The line most likely exists in two crontabs — for example your user crontab and root's, or duplicated under /etc/cron.d. List all of them and remove the extra copy.
Could daylight saving cause a double run?
Yes. When clocks fall back one hour, jobs scheduled inside the repeated 01:00-01:59 window fire twice. Move them outside that hour or run cron in UTC.
How do I stop overlapping runs?
Use flock: prefix the command with /usr/bin/flock -n /tmp/myjob.lock so a second instance exits instead of running alongside the first.