View all posts

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:

crontab -l

Using the following command, you can edit the cron task list:

crontab -e

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]

That’s it!

Related Articles...

Install LAMP

How to install LAMP Stack on Ubuntu 20.04

What is LAMP? The LAMP acronym stands for Linux, Apache, MariaDB/MySQL, and PHP, all of which are free and open source. It is the most commonly used software stack for dynamic websites and web applications. The operating system is Linux, the... Read more

This website uses cookies

We use cookies for the analysis of our visitor data, to improve our website, and to give you a great website experience. For more information about the cookies we use, please see our cookie policy.