Linux: Run Cron Job When System Reboot or Startup

This post will guide you how to run command or cron jobs after system reboot or startup in your Linux system. How do I run command at startup on crontab under CentOS/RHEL/Ubuntu Linux system. How to run a cron job automatically when your system reboot in Linux. How to execute commands or your own scripts during system reboot or startup.

Run Cron Job When System Reboot


If you want to schedule cron jobs to run everytime after system reboot or start in Linux, you need to use an option called @reboot in /etc/crontab configuration file, and it allow you to run a cron job when the system reboot.

For example, you want to run the /root/fio.sh scrpt file one time after the system restarts, you need to add the cron job entry into the /etc/crontab file. Just do the following steps:

#1 type the following command to edit crontab file.

#crontab -e

#2 adding the following line into crontab file.

@reboot /root/fio.sh

#3 save and close the crontab file.

If you want to get more information about the options of crontab, you can type the following command under CLI:

#man 5 crontab.

You will see that there are other special time specification you can use in your cron jobs. Like this:

@reboot : Run once after reboot.

@yearly : Run once a year, ie. "0 0 1 1 *".

@annually : Run once a year, ie. "0 0 1 1 *".

@monthly : Run once a month, ie. "0 0 1 * *".

@weekly : Run once a week, ie. "0 0 * * 0".

@daily : Run once a day, ie. "0 0 * * *".

@hourly : Run once an hour, ie. "0 * * * *".

These special time specification “nicknames” which replace the 5 initial time and date fields, and are prefixed with the ‘@’character.

 

You might also like:

Sidebar



back to top