How to Run Cron Jobs Every 10, 20, or 30 Minutes?

The cron job is a time-based job scheduler in Unix-like operating systems for maintaining the software environments to run periodically at fixed times, days, dates, or intervals. The Cron jobs can be easily scheduled in the time sequence followed by minute, hour, day, or month format.

This guide provides a deep insight into the possible ways to run cron jobs every 10, 20, or 30 minutes interval. The outcomes of this guide are written below:

Let’s start with accessing the crontab file.

Prerequisites: Access the Crontab File

The objective of the “Crontab” file is to schedule the defined commands for execution periodically. Before scheduling the cron job, first, create the crontab file, as it is not available by default. For this purpose, use the following “crontab” command:

$ crontab -e

If the user is creating it for the first time, then it will ask to select the text editor. In this case, the first “/bin/nano” default editor is selected by passing the “1” integer in the terminal.

The new crontab file “/tmp/crontab.6xeBOB/crontab * ” is created, as shown in the above image.

Crontab Syntax

The generalized syntax to run the cron job crontab is written below:

* * * * * command

The syntax specifies “five-asterisks” that display the time and then the desired command that needs to be executed. However, the time is further divided into five sections:

  • The first asterisk* identifies “minutes(0-59)”
  • The second asterisk* denotes “hours(0-23)”
  • The third asterisk* specifies the “day of the month(1-31)”
  • The fourth asterisk* shows the “month(1-12)”
  • The fifth asterisk* leads to the “day of the week(0-7)”

How to Run CronJobs Every 10 Minutes?

Type the following line at the end of the above “/tmp/crontab.6xeBOB/crontab * ” crontab file to run the particular “echo” command as a cron job every 10 minutes:

*/10 * * * * echo "Welcome to Linux at $(date)" >> $HOME/Message.txt

How to Run CronJobs Every 20 Minutes?

Same as the above section, add the below-mentioned line into the crontab file that will execute the Sample.sh” after every 20 minutes:

*/20 * * * * /home/itslinuxfoss/Sample.sh

How to Run CronJobs Every 30 Minutes?

Simply add the below-written line into the above crontab file for the execution of the “New.sh” script after every 30 minutes:

*/30 * * * * /home/itslinuxfoss/test/New.sh

Alternative method: Using the Comma(,) Operator

The user can also run the above-specified cron jobs every 10,20 and 30 minutes by utilizing the “comma” operator followed by the below-mentioned series of minutes:

For 10 Minutes:

0,10,20,30,40,45,50,* * * * command

For 20 Minutes:

0,20,40,60,80,100,120 * * * * command

For 30 Minutes:

0,30,60,90,120,150,180 * * * * command

It is recommended to use the “sash(/)” operator as it is quite a bit convenient as compared to typing a large number of series.

Conclusion

The cronjob can be run every 10, 20, or 30 minutes by utilizing the “slash(/)” and the “comma(,)” operators in Linux. To create a cron job, access the “crontab” file and add the specified commands. The crontab file can be created or opened through the “crontab -e” command. This guide has briefly described the possible aspects of scheduling the cron job every 10, 20, or 30 minutes.