/sc_assets/3664/logo.png

Select a topic:

Choose from one of the topics below to browse other articles

Articles & Information.

Automating tasks with cron

You can use cron to run repeated tasks on your server. Cron jobs are defined in a file, known as a 'crontab', and run as often as you specify. A cron entry looks like this:

	5 * * * * curl https://lasershark.uk

The crontab line is broken down into these parts:

Just specify the number that represents the time you want the task to run, for example 5 * * * * for every hour at :05. You can separate multiple values with commas, so 1,31 * * * * will run the task at :01 and :31 past every hour.

You can also use a divisor. For example, instead of configuring a job to run at :00, :15, :30 and :45, you can just type */4 * * * *. You can also use a range, such as 0 9-17 * * *, to make a job run every hour between 09:00 and 17:00.

Adding a cron task

To add a task to your crontab, type crontab -e at the command line. This will open your crontab in your default editor—if it's the first time you've done this, on some systems you might be asked to choose a default editor (we recommend nano)—and you can add your cron jobs to the end of this file.

Remember, your crontab will run as the currently logged-in user, so if you need a task to run as root, log in as root or run sudo crontab -e.