- Trending Categories
- Data Structure
- Operating System
- C Programming
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How would I get a cron job to run every 30 minutes on Linux?
In order to create a crontab job to run every 30 minutes we first need to explore and understand what a crontab job is.
A crontab is nothing but a list of commands that we can run during a cron job. A cron job is a utility that schedules automatic execution of commands at specific times.
We can start a cron job with the help of bash script by following the commands shown below −
This will open a file which you can edit, insert the cron job shell script in the above file and then close that file.
Just insert the code shown below in the above file
* * * * * sample.sh
The above command contains 5 *, where each * indicates the time and then follows the stars. We have the script which we want to run as a cron job. In the sample.sh we need to write the following command to make the environment variables available to it.
Now we understand how we can create a crontab job, it is time to understand what these * actually mean and how we can replace their values to solve our particular question.
The five * in the above command actually has a separate meaning attached to them.
These mainly mean −
Seconds: 0-59 Minutes: 0-59 Hours: 0-23 Day of Month: 1-31 Months: 0-11 Day of Week: 0-6
Now that we know what the cron job actually means and how it works, it’s time that we understand how we can make a cron job run every 30 minutes.
While there are different variations possible for the same result, the most basic command that will make sure that a job runs when the minute of each hour is 0 or 30 is shown below
0,30 * * * * sample.sh
The above command will make sure that the sample.sh bash script will run when the minute of each hour is 0 or 30 (like it would run at 2:00, 2:30, 3:00).
- How to Run a Cron Job Every Day on a Linux System
- How to run a crontab job every week on Sunday?
- How to Create a Cron Job and Execute at a Given Time in Linux
- How to test a weekly crontab job on Linux?
- How to add 30 minutes to datetime in MySQL?
- Run Linux Natively on Windows 10
- How can I run a Linux command using Python CGI script?
- How to Add Cron Jobs to A Specific User in a Linux System
- The Linux Job Market
- How to use Boto3 library in Python to run a Glue Job?
- How to run a method every 10 seconds in Android?
- Show android notification every five minutes?
- How do I run a command on an already existing Docker container?