Crontab expression to run cron job every 5 minutes
The crontab expression to run a cron job every 5 minutes is ’*/5 * * * *’
Alternative expression
0,5,10,15,20,25,30,35,40,45,50,55 * * * *
Cron jobs are an essential aspect of automating tasks in a Unix-like operating system. These jobs allow users to schedule repetitive commands or scripts on their systems. Often, users need to schedule tasks to run at specific intervals, such as every 5 minutes.
Rules of Cron Expression Syntax
| - - - - - - Minute (0-59)
| | - - - - - - Hour (0-23)
| | |- - - - - Day of the month (1-31)
| | | | - - - Month (1-12)
| | | | | - - Day of the Week (1-7, Monday to Sunday)
* * * * *
The crontab expression consists of five fields, each representing a different time element: minute, hour, day of the month, month, and day of the week. In the case of running a cron job every 5 minutes, the first field (minute) is set to */5. This means that the cron job will run every minute that is divisible evenly by 5.
Using this expression, you can schedule various tasks to run on a schedule, whether it’s checking for updates, processing data, or running backups. It provides a simple and efficient way to automate recurring tasks, ensuring that they are executed at the desired intervals.
Other ways to execute a cron job every 5 minutes
| Expression | Description |
|---|---|
*/5 * * * 0 | EVERY 5 MINUTES, ONLY ON SUNDAY |
*/5 2-3 * * * | EVERY 5 MINUTES, BETWEEN 02:00 AM AND 03:59 AM |
*/5 * * 2 * | EVERY 5 MINUTES, ONLY IN FEBRUARY |
*/5 * 1 * * | EVERY 5 MINUTES, ON DAY 1 OF THE MONTH |
*/5 13-16 * 3 * | EVERY 5 MINUTES, BETWEEN 01:00 PM AND 04:59 PM, ONLY IN MARCH |
FAQ
Q: What is a cron job?
A cron job is a task or script that is scheduled to run periodically on a Linux system. It is commonly used for automating repetitive tasks.
Q: How do I schedule a cron job to run every 5 minutes?
To schedule a cron job to run every regurlarly on the 5 minute mark, you need to edit the crontab file by running the command:
crontab -e
Then, add the following line to the crontab file:
*/5 * * * * command_to_run
Replace command_to_run with the actual command or script you want to execute.
Q: Can I specify a specific day of the week to run the cron job every 5 minutes?
Yes, when using the */5 * * * * cron expression, the job will run every 5 minutes, regardless of the day of the week. However using */5 * * * 7 will run it every 5 minutes only on Sunday
Q: How can I run a cron job every 10 minutes instead of every 5 minutes?
To run a cron job every 10 minutes, you can modify the cron expression to:
*/10 * * * *
This will execute the job every 10 minutes.
Q: Are there any other commonly used cron expressions?
Yes, there are several commonly used cron expressions, such as:
0 * * * *: Executes the job every hour.
0 0 * * *: Executes the job every day at midnight.
0 0 * * 0: Executes the job every Sunday at midnight.
Q: Can I schedule multiple cron jobs to run every 5 minutes?
Yes, you can schedule multiple cron jobs to run every 5 minutes by adding multiple lines to the crontab file.