How to run a cron job automatically at boot
System tasks and processes are scheduled using the Cron daemon in Linux. Scheduled jobs are stored and read using crontab tables (crontab).
Using the crontab command, you can control when and how jobs are executed. By using crontab, you can set the execution time of a job down to the minute, without having to write loops and timing logic.
By using the following command, you can view the cron task list:
Using the following command, you can edit the cron task list:
When you have multiple text editors installed, the system prompts you to pick one for updating the cron task list. Just select your preferred option using the number between brackets. Our default option will be vim.
Add a line called @reboot to the task list if you want your cron job to run at every system boot. At startup, the job specified by this string starts immediately after Linux is rebooted.
The syntax for an @reboot string is:
@reboot [path to command] [argument1] [argument2] … [argument n] @reboot [path to shell script]
If you wish to run a job with a delay after the reboot, add the sleep command to the @reboot string:
@reboot sleep [time in seconds] && [path to job]