Tutorial

Crontab @reboot.

@reboot in a crontab runs a command once when the system starts. It's the quickest way to start a script at boot, with a few catches worth knowing.

How to use it

crontab -e
@reboot /home/alice/start-worker.sh >> /home/alice/start-worker.log 2>&1

@reboot replaces all five time fields. It works in your own crontab and in system crontabs (/etc/crontab, /etc/cron.d/, where a user field follows it).

When exactly does it run?

When the cron daemon starts, not when the machine "finishes" booting. Debian's manual warns that this may be before some other system services have started. So a script that needs the network, a database or a mounted disk can fail at boot even though it works when you run it by hand.

The simple workaround is to wait:

@reboot sleep 60 && /home/alice/start-worker.sh >> /home/alice/start-worker.log 2>&1

A sturdier one is to have the script wait for what it needs (for example, retry until the database answers) instead of guessing a delay.

Restarting cron doesn't re-run @reboot jobs

Both main Linux crons make sure @reboot jobs run once per boot, not every time the cron service restarts:

  • Debian and Ubuntu create /run/crond.reboot the first time. If it already exists (cron was restarted), they log Skipping @reboot jobs -- not system startup. /run is cleared at every boot.
  • cronie (Fedora, RHEL, Arch) does the same with a cron.reboot lock file in its run directory, logging @reboot jobs will be run at computer's startup. when it skips them.

So to test an @reboot job you have to actually reboot, or just run the command by hand.

Why isn't my @reboot job running?

  • It ran, but too early. Check its log file; add a delay or a wait loop as above.
  • Command not found. Cron's PATH is /usr/bin:/bin. Use full paths (more).
  • No log, no clue. Without the >> file 2>&1 redirect, output goes to email and is usually lost. See where cron logs go.
  • Wrong scheduler. @reboot is a Linux/Unix cron feature. Kubernetes CronJobs, GitHub Actions, Spring and the cloud schedulers don't support it (which ones support which @ shortcuts).

Better on systemd: a service unit

If the job needs the network, a systemd service can wait for it properly:

# /etc/systemd/system/start-worker.service
[Unit]
Description=Start worker at boot
Wants=network-online.target
After=network-online.target

[Service]
Type=oneshot
User=alice
ExecStart=/home/alice/start-worker.sh

[Install]
WantedBy=multi-user.target
sudo systemctl daemon-reload
sudo systemctl enable start-worker.service

Its output goes to the journal (journalctl -u start-worker). On a Mac, use a launchd job with RunAtLoad instead (see crontab on Mac).

Sources

Checked against these official manuals and source code. Last verified 18 November 2026.