Linux: Run Cron Job on Reboot

Objective: Run or execute a cron job after a reboot or system startup.

cron is a daemon to execute scheduled tasks on Unix and Unix-like operating systems. The Vixie cron implementation, which is included in many Linux distributions supports additional nonstandard scheduling definitions. One of them is the @reboot entry.

To run a cron job after every reboot on Vixie cron, add the following crontab entry. You can modify your crontab by running crontab -e.

If the above crontab entry does not get executed after a system reboot, most probably you are using another implmentation of cron and not using Vixie cron.

There is no standard way of knowing if you are running Vixie cron. Below is how I usually determine if Vixie cron is being used.

The other method is to run man cron and check if Paul Vixie is stated as the author of the cron implementation.

You can refer to man -s 5 cron for the list of special strings supported by Vixie cron. Below is an extract from the man page.

If the system is not rebooted and if the cron daemon process gets restarted, the cron daemon is smart enough not to run the @reboot jobs. I did a simple test (on Ubuntu 16.04 LTS) by restarting the cron daemon and below is the output from the syslog file.

Vixie cron is available on both Linux and BSD systems.

ibrahim = { interested_in(unix, linux, android, open_source, reverse_engineering); coding(c, shell, php, python, java, javascript, nodejs, react); plays_on(xbox, ps4); linux_desktop_user(true); }