Hi everyone, this time I want to share information about the rules on CronJob. For some developers, SysAdmin or DevOps may already know what Cronjob is. Cronjob is a software that runs a process or program that has a predetermined execution time. So in this cronjob we can set up the commands that we usually run in the Linux terminal at the time we want. for example, we want to restart the service regularly every day, all of that can be set at cronjob. for the rules of the cronjob are as follows:
Minute Hour Date Month Day | | | | | | | | | | | | | | | Command: * * * * * [command]
Explanation:
there are 5 blocks of time available in the cronjob rules as above, here are the details:
- Minutes: we can set the value for the minutes 0 – 59, if we give * it means that it will run every minute
- Hours: we can set the clock to 0- 23, if we give * it means that it will run every hour
- Date: we can set it on 1 – 31, if we give * it means that it will run on every date
- Month: we can set up in month 1 – 12 (January – December), if we give * it means that it will run every month
- Day: we can set the values 0 – 6 (0 = Sunday, 1 = Monday, etc.), if we give * it means that it will run every day
special operators on cron:
- * : This means “Every Time”, if we put it in the minute block, it means every minute, when it is installed in the hour block, it means every hour, and so on.
- – : this means “Range”, we can use it to determine the timeframe, for example we install cron
0 7-12 * * *
, it means that the command will run every hour in the time span of 7 to 12. - , : This means “Some Time”, we can use it to determine some time, for example we install cron
0 7,9,11 * * *
that means the command will run at 7:00, 9:00 and 11:00. - / : This means “Each time is determined”, we can use it to determine each time specified, for example we install cron
*/15 * * * *
that means we run every 15 minutes.
Yes, those are the rules on cron that I know, here is an example of using cronjob that I often use:
#Setting timzone Asia / Jakarta so that execution time follows WIB CRON_TZ="Asia/Jakarta" #Executes commands every minute continuously * * * * * [command] #Executes commands every day at 7 am and 10 pm 0 7,10 * * * [command] #Executes a command every 30th minute between 8 and 12 o'clock 30 8-12 * * * [command] #Executes a command every 20 minutes at 7 o'clock and between 10 and 12 o'clock*/15 7,10-12 * * * [command] #Execute commands at 7:00 am on August 17th 0 7 17 8 * [command] #Execute commands at 7:00 am and 10:00 pm every Monday to Friday 0 7,22 * * 1-5 [command]
Yes, that’s all from me, hopefully it’s useful for all readers, if there is an error or someone wants to add, please tell me, thank you ^^.
0 Comments