Crontab @reboot — Run Once at Startup
Use the @reboot directive to run a command once when the cron daemon starts, typically at system boot. Not a time-based schedule.
Detailed Explanation
Using @reboot in Crontab
The @reboot directive is a special cron string that runs a command once when the cron daemon starts. This typically corresponds to system boot, but it also triggers if the cron service is restarted.
Syntax
@reboot /path/to/script.sh
There is no equivalent 5-field expression for @reboot — it is a unique directive.
How It Works
When the cron daemon initializes (usually at boot time), it scans all crontab files for @reboot entries and executes them once. After that, these entries are not triggered again until the next restart.
Important Considerations
Not all cron implementations support @reboot. It works on Vixie cron (the most common on Linux) but may not be available on all Unix systems.
Environment differences: At boot time, the system environment may be different from a normal login session. Network interfaces, mounted filesystems, and services may not be available yet. Consider adding a delay:
@reboot sleep 30 && /scripts/start-app.sh
- Service managers: For production applications, consider using systemd, Supervisor, or Docker instead of
@reboot. These provide better process management, logging, and automatic restart capabilities.
Common Use Cases
@reboot /home/user/start-screen-session.sh
@reboot /opt/app/start-worker.sh >> /var/log/worker.log 2>&1
@reboot sleep 60 && /scripts/check-services.sh
Use Case
Use @reboot for starting background services that do not have systemd unit files, launching screen or tmux sessions, initializing development environments, starting monitoring agents, or running one-time setup scripts after a reboot.