Categories
Linux Commands

How to Run Cron Job Every 5, 10 or 15,20 Minutes

How to Run Cron Job Every 5, 10 or 15 Minutes

Introduction

The Cron daemon is a built-in Linux utility that runs processes on your system at a scheduled time. Cron reads the crontab (cron tables) for predefined commands and scripts.

By using a specific syntax, you can configure a cron job to schedule scripts or other commands to run automatically.

This guide shows you how to set up a cron job in Linux, with examples.

In Linux, a cron job means a task that should execute at defined intervals. You can set interval of a minute, hour, day of the week, month, day of the month, or in any combination of these units. In this tutorial we will show you how to run cron job in Linux system.

The Cron jobs are mostly used to do automatic task like backing up data or databases, update the system with latest security patches, sending emails, monitor system and more. Commonly, cron job runs at every 5, 10, or 15 minutes intervals.

Crontab Syntax

Crontab is a text file that contains the schedule of the cron jobs. You can create, view, modify or delete with crontab command.

In the crontab tab file you should defined separate line for each cron. Each line contains six fields separated by a space followed by the command to be run:

* * * * * command(s)
^ ^ ^ ^ ^
| | | | |     allowed values
| | | | |     -------
| | | | ----- Day of week (0 - 7) (Sunday=0 or 7)
| | | ------- Month (1 - 12)
| | --------- Day of month (1 - 31)
| ----------- Hour (0 - 23)
------------- Minute (0 - 59)

You can define following operators for first five fields (time and date):

Create / Modify crontab file

If the crontab file not exists or want to modify then you can use crontab -e command.

Run a Cron Job Every 5 Minutes

To run cron job at every five minutes you should use the step operator and add the following line to crontab file:

*/5 * * * * command

Here, */5 means create a list of all minutes and run the job for every fifth value from the list.

You also can run cron job at every five minutes using comma operator by creating list of minutes:

0,5,10,15,20,25,30,35,40,45,50,55 * * * * command

The first method is easy to use and recommended.

Run a Cron Job Every 10 Minutes

Append the following line to run cron job at every 10 minutes interval:

*/10 * * * * command

Run a Cron Job Every 15 Minutes

Add the following line to run cron job at every 15 minutes interval:

*/15 * * * * command

Run a Cron Job Every 20 Minutes

Add the following line to run cron job at every 20 minutes interval:

*/20 * * * * command

Conclusion

In this guide you learned how to run a cron job at every 5, 10 and 15 minutes interval.

If you have any question, feel free to leave a comment below.


Source

Leave a Reply

Your email address will not be published. Required fields are marked *