CronNudge

Published October 21, 2026

Cron Job Running Twice? How to Find the Duplicate

Two runs at the same minute are usually two schedulers, or one schedule that matches more often than the line looks. Cron itself does not start a second copy of a single line in the minute it already matched. It wakes every minute and runs each matching command once.

Prove that before you change the schedule. One process that prints two lines, or a wrapper that calls the command twice, looks like a double run in the job log and is one start in the cron log. A long run that is still alive when the next minute matches is a different problem: that is overlap, and the lock is in prevent overlapping cron jobs. A job that never starts is crontab not running. The heartbeat pattern is how to monitor cron jobs.

Prove it is two runs

Have the job print one line that only it can produce: a timestamp, the hostname, and the process id.

echo "$(date -u +%Y-%m-%dT%H:%M:%SZ) $(hostname) $$ start"

Two of those lines, with two hostnames or two pids, are two processes. One line, followed by the same work twice, means this process called the work twice. Read the command cron actually started before you edit the script.

The daemon log

Debian's cron logs to the syslog facility cron. Where rsyslog is installed, that is /var/log/syslog:

grep CRON /var/log/syslog

The daemon's log_it writes (user) CMD (command). The child that runs the job is renamed to uppercase, which is what shows up in syslog, so a start looks like CRON[12345]: (deploy) CMD (/usr/local/bin/backup.sh). The unit is cron:

journalctl -u cron --since today

Newer Debian installs do not ship rsyslog, so there is no /var/log/syslog. The journal command is the one that still works. More of the line format, including cron's -L levels, is in where cron logs are.

cronie (RHEL, Fedora, Rocky, Alma) writes the same shape, tagged CROND, to /var/log/cron when rsyslog is there. The unit is crond:

journalctl -u crond --since today

cronie logs that line once it knows the pid the command's shell will get, so the number in brackets is that shell. A root crontab, or a system crontab, may start the line with - (-0 3 * * * /usr/local/bin/backup.sh). cronie then does not write the syslog line for that command. A missing CMD line can be that dash. It is not proof the command was skipped.

Two CMD lines in the same minute, with two pids, are two starts. One CMD line and two host-and-pid lines from the script means the command in parentheses is a wrapper. While a run is in progress, GNU ps shows the parent chain:

ps -ef --forest

The job's parent should be the shell that cron started. Two shells with two different cron parents are two daemons. One cron parent and two shells means that daemon matched two lines.

The same command in two places

Debian cron reads every user's crontab, /etc/crontab, and /etc/cron.d. User crontabs have no user field. /etc/crontab and /etc/cron.d do. The spool files are not meant to be edited by hand. List them with crontab:

crontab -l
sudo crontab -u root -l

crontab -u is the documented form. It names whose table you are listing. sudo crontab -l with no -u is root's table, which is a different file from yours.

Debian's /etc/crontab also runs run-parts on /etc/cron.hourly, /etc/cron.daily, /etc/cron.weekly, and /etc/cron.monthly. Those scripts have to be executable and named with letters, digits, underscores, and hyphens. A name with a dot is skipped. The daily, weekly, and monthly run-parts lines are turned off when anacron is installed, so that anacron is the daemon that runs those directories. Hourly stays with cron. A script in /etc/cron.daily and the same command in a user crontab are still two runs: anacron took the directory, it did not take the user line. When that directory runs is /etc/cron.daily not running.

Search all of those places for the command. Not every hit is a live second schedule. Debian cron skips a cron.d file whose name contains a dot, and a cron.daily script that is not executable. The filename rules are in crontab not running.

cmd=backup.sh
{
  crontab -l
  sudo crontab -u root -l
  sudo cat /etc/crontab /etc/cron.d/*
  sudo grep -R -n -F -e "$cmd" \
    /etc/cron.hourly /etc/cron.daily /etc/cron.weekly /etc/cron.monthly
} 2>/dev/null | grep -F "$cmd" || true

Delete the copy you did not mean to keep. One definition, in one file.

A deploy that appends

Pasting the line twice does this inside one file. So does a provisioner that appends on every run:

(crontab -l; echo '0 3 * * * /usr/local/bin/backup.sh') | crontab -

Each deploy adds another copy. Debian's crontab(1) also documents that crontab -l | crontab - keeps duplicating the three-line "DO NOT EDIT THIS FILE" header when CRONTAB_NOHEADER=N. The default on Debian is to omit that header. Leave the variable unset, and install the job line so a second run replaces it instead of appending:

line='0 3 * * * /usr/local/bin/backup.sh'
( crontab -l 2>/dev/null | grep -vxF -- "$line"
  echo "$line"
) | crontab -

-x requires the whole line to match, and -v drops those lines, so a different command that merely contains the same words stays. The echo puts one copy back. Run it twice and crontab -l still shows the line once.

Two daemons, or a timer as well

pgrep -a cron prints the pid and the command line. Read the command. The name match also hits crontab and anacron, which are not a second scheduler for your line. What you are looking for is two daemons that both read a crontab: cron and crond on one host, or the host's cron and a container whose image also runs cron and mounts the same crontab. The container case is cron in Docker.

A systemd timer is a second scheduler even when only one cron daemon is running. List every timer:

systemctl list-timers --all

If a timer's unit runs the same script as a crontab line, both will start it. The timer's own unit is in systemd timers.

The schedule itself fires more than once

Cron examines each entry once a minute and runs it when the minute, hour, and month match, and at least one of the two day fields matches. One matching line starts one process in that minute.

Both day fields restricted means or, not and. Debian's crontab(5) and cronie's crontab(5) use the same example: 30 4 1,15 * 5 runs at 04:30 on the 1st and the 15th, and on every Friday. On a Friday that is also the 1st, both fields match and the line still runs once. The extra runs are the other Fridays, not a second process at 04:30. If either day field is *, only the other one applies.

*/30 in the minute field and 0,30 are the same minutes, 0 and 30. Two lines, one of each, are two processes. One of those lines is not. cronie's notes use */35 for the case people misread: it runs at minute 0 and minute 35, twice an hour, not every 35 minutes. A star in the wrong field is the other misread. * */2 * * * is every minute of every even hour. 0 */2 * * * is minute 0 of those hours.

Paste the line into the cron tool and read the next runs. If the tool shows the times you are seeing, the schedule is doing what it says. The duplicate is not a second daemon.

The clock fell back

A fixed minute and hour, with no * in either field, is not started again by Debian cron when the clock moves back by less than three hours. Jobs with a wildcard in the minute or hour follow the new clock, so a */15 line runs on both passes of the repeated hour. cronie's crontab(5) also says a time that occurs twice matches twice. That sentence is the field match. The jump itself is cron(8), and the hour that repeats depends on the zone. The cases are in cron jobs and daylight saving time.

The previous process is still alive

That is overlap, not a second schedule. flock -n on one host runs the command only when it can take the lock, and exits 1 without starting it otherwise. The lock drops when the process exits.

flock -n /var/lock/backup.lock /usr/local/bin/backup.sh

It does nothing for a second host. The rest of the lock, including a database session, is in prevent overlapping cron jobs.

The same crontab on several hosts

Each machine runs its own cron, against its own copy of the files. An image with a crontab in it, a config-management run that installs the same line everywhere, or an autoscaling group that boots that image, fires once per machine. During a deploy, the old instance and the new one are both machines. Both fire until one of them is gone.

flock on a local disk is a lock the other machine cannot see. The check has to be something both of them share, below, or the crontab has to be installed on one machine only.

A scheduler inside every process

These are the same shape: the schedule lives in the application, and every process that starts it will fire.

Celery's periodic-task docs say to run a single scheduler for a schedule, or you get duplicate tasks. celery worker -B embeds beat in the worker, so two replicas are two schedulers. Run beat as its own process, one replica. The rest is Celery beat.

APScheduler's FAQ says a job store must not be shared between worker processes. Sharing one produces duplicate execution, because there is no lock between those processes. Two gunicorn or uvicorn workers that each start a scheduler are two schedulers. Run it in one dedicated process. The rest is APScheduler.

node-cron's cron.schedule runs in the process that called it. Several Node processes, PM2 instances, or pods each fire, unless that task sets distributed: true, which the README uses so one instance runs each fire. The rest is BullMQ, node-cron, and Agenda.

Spring runs @Scheduled in each application that has @EnableScheduling. Two pods are two runs. Spring does not ship the lock. A lock both pods can see is a separate library, covered in Spring scheduled tasks.

Quartz's RAMJobStore keeps the schedule in that JVM's memory. Clustering only works with a JDBC job store, and org.quartz.jobStore.isClustered set to true, with one node firing each time. Two processes on the in-memory store are two schedulers. The rest is Quartz.

Kubernetes CronJob

concurrencyPolicy is optional and defaults to Allow, so overlapping Jobs from that CronJob all run. Forbid skips the new Job when the previous one has not finished. Replace cancels the running Job and starts another. The policy applies only to Jobs created by that same CronJob. A second CronJob, in another namespace or from a second install of the same chart, is always allowed to run at the same time.

The concept page says a CronJob creates a Job approximately once per execution time. Two Jobs can be created, or none. Kubernetes tries to avoid that and does not promise to prevent it, so the Job should be idempotent. With Allow and startingDeadlineSeconds left unset or set large, the same page says the Jobs will always run at least once. The manifest and the ping are in Kubernetes CronJobs.

A hosted scheduler that says at least once

Cloud Scheduler's overview says delivery is at least once: in some rare cases one scheduled execution runs more than once, and the target should be idempotent. A later schedule does not start while that attempt is still running. The API holds the next execution until the current one finishes or times out. Deduplicate with X-CloudScheduler-JobName and X-CloudScheduler-ScheduleTime. ScheduleTime stays the same across retries of that run.

EventBridge Scheduler's docs say it provides at-least-once delivery to the target, meaning a delivery that gets a response, and that it retries a failed invocation. A target that did the work and then failed the response can be called again for that attempt. Make that retry safe. The Lambda schedule itself is in EventBridge scheduled Lambda.

Make the second run harmless

Stopping the extra scheduler is the fix when you find one. The job still has to survive the case you have not found yet: two hosts for a minute during a deploy, a retry after the work succeeded, the Kubernetes case above.

On one host, flock -n is the skip. Across hosts, take a lock both of them can see, or refuse to do the work twice for the same slot.

PostgreSQL pg_try_advisory_lock(bigint) takes an exclusive session-level lock if it can, and returns true. It returns false immediately when another session holds that same key. The number is one you choose. The lock stays with that database session until you unlock it or the session ends, so the connection has to stay open for the work. A pooled connection that goes back to the pool still holds the lock.

SELECT pg_try_advisory_lock(42001);

A unique row for the slot is the "already done" check. This is PostgreSQL, and it needs a unique constraint on (job_name, slot). An empty RETURNING means this slot was inserted already. Skip the work.

INSERT INTO job_slot (job_name, slot)
VALUES ('nightly-report', '202611170300')
ON CONFLICT (job_name, slot) DO NOTHING
RETURNING job_name;

The slot is the scheduled time, not the time the process happened to start. Two starts in the same minute then collide on one row. A retry of a finished slot collides too.

What CronNudge shows

CronNudge cannot see your crontabs, your hosts, or your processes, and it cannot stop the second run. It only knows about pings it receives. The ping URL is https://cronnudge.com/ping/<check-id>. GET, POST, and HEAD all count. The response is text/plain ok with Cache-Control: no-store.

Turn on "Track start and finish". Setting Max runtime (seconds) or Duration deviation % turns run tracking on as well. Overlap is evaluated only when run tracking is on. Free includes that on 3 checks. Pro removes the cap. Free is 10 checks, a 5-minute minimum, and email plus one Slack or Discord channel. Pro is $12 a month for 100 checks, a 1-minute minimum, signed webhooks, and the API. The numbers are on pricing. The fields are in assertions, runs, and agents.

/start records a start. It is not a success. A second /start while a tracked run is still open sends an overlap alert. The alert says the check started again before the previous run finished. That alert does not, by itself, mark the check down, and it does not close the first run. A success or /fail closes every open run. A paused check stores the ping and does not alert.

Two success pings do not raise an overlap alert. If both copies finish and only the success URL is called, the check stays up. A success while the check is already up does not send another down or recovery alert. The duplicate is visible as two rows, not as a page.

Recent pings on the check lists up to 40 rows: the kind, the exit code when one was sent, a relative time, and the duration when the run was tracked. Anything under 10 seconds reads "just now", so two pings a second apart both say that while you are looking. The list does not show the user agent, the IP hash, or the body. Those are stored (the user agent cut at 200 characters, the IP as a hash). The API list, GET /api/v1/checks/{id}/pings, returns up to 100 pings with kind, an ISO at, exitCode, durationMs, and body. It does not return the user agent or the IP hash. The ISO time is what separates two pings that the page still calls "just now". The API is on Pro.

The Runs list is the other place a double start shows. With run tracking on, the second start is a run whose status line includes "overlap".

An Idempotency-Key header is cut at 128 characters and stored per check, not per path. The same key on a later request is a replay: no second row, no second alert, and no overlap alert. A curl --retry of one request should reuse its key. /start and the success ping need different keys, or the success is swallowed as a replay of the start. A real second run that reuses the start's key is also swallowed, which is what you want when the key is the scheduled slot and you do not want the duplicate to count. It is what you do not want when you wanted the overlap alert. Put the hostname in the key, or send no key, when the second start should alert.

% in a crontab command is a newline unless you escape it as \%. The rule is in crontab not running. This line pings /start, runs the job, and pings success. The slot key is the UTC minute. A second start in that same minute replays. Set CRONNUDGE_URL in the crontab to the ping URL with no /start on the end.

0 3 * * * slot=$(date -u +\%Y\%m\%d\%H\%M); curl -fsS -m 10 --retry 3 -o /dev/null -H "Idempotency-Key: ${slot}-start" "$CRONNUDGE_URL/start" || true; /usr/local/bin/backup.sh && curl -fsS -m 10 --retry 3 -o /dev/null -H "Idempotency-Key: ${slot}-ok" "$CRONNUDGE_URL"

FAQ

Why does my cron job run twice? One crontab line runs once per matching minute. Two processes at that minute come from two lines, two crontabs (yours, root's, /etc/crontab, /etc/cron.d, or a cron.daily script), two daemons, a systemd timer as well as cron, or the same file on two machines. A schedule with both day fields set also runs on extra days. A wrapper that calls the command twice is one CMD line and two pids in the job's own log.

Can daylight saving time make cron run twice? A wildcard minute or hour follows the clock, so it runs on both passes of the repeated hour. A fixed minute and hour is not re-run by Debian cron when the clock falls back by less than three hours. cronie's crontab page says a repeated time matches twice, and its cron page is the rule for the jump. The hour that repeats depends on the zone.

Why does my Kubernetes CronJob create two Jobs? The CronJob documentation says creation is approximately once per scheduled time: two Jobs can be created, or none. concurrencyPolicy defaults to Allow, which lets those Jobs run together. Forbid only applies to Jobs from that same CronJob. A second CronJob object is not covered by it. The Job should be safe to run twice.

Why does Celery beat send duplicate tasks? Beat publishes once per scheduler process. Celery's periodic-task docs say a schedule needs a single scheduler, or you get duplicate tasks. Two beats, or two workers started with -B, each publish. Run one beat. A long task can also still be running when the next tick is published. That overlap is separate from a second beat.

How do I stop a cron job running twice on multiple servers? Install the crontab on one machine, or take a lock both machines can see. flock on a local file does not. A Postgres advisory lock is held by the database session, and a unique row for the scheduled slot makes the second insert do nothing. The work still has to be safe when the lock is wrong.

Will a monitor tell me a job ran twice? Only from the pings it received. With run tracking on, a second /start while a run is open is an overlap alert. Two success pings are two rows and no overlap alert. An Idempotency-Key equal to the scheduled slot makes the second request a replay, so it is not recorded twice and it does not alert. CronNudge cannot see the crontab and cannot stop the extra run.


Find the second scheduler, then make the work safe when it still happens. Create the check, or read the next runs on the cron tool.