Menu

Saturday, November 13, 2021

How to run cron jobs every 5, 10, 15 or 30 minutes and every hour, day, week, month


Cron is a software utility or Linux command also recognized as a Cron job used to schedule tasks or jobs to be executed after a fixed interval of time in the future. The Cron jobs are mostly used for scheduling tasks on the server for automating the administration and system maintenance tasks. The Cron jobs can be scheduled to run every minute, hour, day, or month and we will learn how to run a Cron job after every 10, 20, or 30 minutes in this post. Let’s start.


Syntax

The syntax for running cronjob is that we first have to mention the time and then specify the command that we want to execute. The syntax for mentioning time is further divided into five fields.

* * * * * command(s)

The first field describes the minute.
The second field describes the hour.
The third field describes the day of the Month.
The fourth field describes the month.
The fifth field describes the day of the Week.


Run a Cron Job Every Minute
every minute : * * * * * /your/command

Run a Cron Job Every 30 Minutes
every 30 minutes : 0,30 * * * * /your/command

Run a Cron Job Every 1 Hour
every 1 hours : 0 */1 * * *  /your/command

Run a Cron Job Every 2 Hours
every 2 hours : 0 */2 * * *  /your/command


You want to run your cron job once a day at a specific time then here is the solution,

Running a cron job at 01:30 AM everyday : 30 1 * * * /your/command


You want to run your cron job every Sunday midnight then here's the solution,

Running a cron job at 00:00 on Every Sunday : 0 0 * * 0 /your/command


Source - Click Here