How to run cron every hour
Scheduling cron jobs every hour
Use the following expression: 0 \ \ \ \ <command to schedule>
# Example using cron to run a monitoring script every hour
0 * * * * /scripts/monitor.shOther variations and examples include:
Every half an hour: \/30 \ \ \ \
At specific minutes:
- Every hour on the hour - 0 \ \ \ \
- Every hour at 30 - 30 \ \ \ \
- Every hour at 15 - 15 \ \ \ \
- Every hour at 5 - 5 \ \ \ \
On different hour-like cadences:
- Every other hour - 0 \/2 \ \ \
- Every odd hour - 0 1-23/2 \ \ \
- Every hour except 3am - 0 0-2, 4-23 \ \ \
Within a range of hours:
- Every hour between 9-5 - 0 9-5 \ \ \
- Every hour starting from 3am - 0 3-23 \ \ \
Rules of Cron Expression Syntax
These examples are indicative of several rules of cron expression syntax:
- A field containing an asterisk (\) means that it will be run from the first to the last of that field
- Ranges of times are indicated by two numbers separated by a hyphen (-) and this range is inclusive
- Following a range with /No. specifies the skips of the numbers value through that range
- A list, with numbers separated by commas , specifies an execution on those intervals
Each of these expressions then take on the following structure:
| - - - - - - Minute (0-59)
| | - - - - - Hour (0-23)
| | | - - - - Day of the month (1-31)
| | | | - - - Month (1-12)
| | | | | - - Day of the Week (1-7, Monday to Sunday)
* * * * *Where each field represents a period of time. In this case, the syntax 0 \ \ \ \ will schedule the cron job for every hour of every day of every month on the hour. This is because numbers indicate the specific time, in this case minute 0, and the asterisk tells the computer to run the job from the first to the last of that field, so every hour of every day of every month.
Which means that with these rules you should then be able to schedule a cron job for any period you want.
What Exactly is a Cron Job?
The cron command line utility is a job scheduler used to schedule regular actions on your computer. Jobs that are scheduled are known as cron jobs and are run periodically at fixed times, dates or intervals. This is often used for things such as scheduling system maintenance, checking broken links or downloading updated files.
For these instructions to run, they should be placed in a cron file which contains commands to be run at the specific times. The default system for this is the cron table or crontab configuration which can be found in /etc/crontab on your computer. Your operating system will then be able to recognise that it needs to perform those actions on the given schedule.
Cron Job Limitations
The shortest time interval possible between jobs is 60 seconds. This means that cron is not suitable when you want to schedule something with more granularity.
Commands to execute specified in a crontab file can only be run on the same computer where the file lives.
There are no auto retry mechanisms if a job fails. This makes cron jobs unsuitable for incremental tasks where one task depends on another. The action will only run at the specified time.
If your use case doesn’t fall under these limitations - cron should work well for you!
Related articles
Bash Comments
Comments will help make your scripts more readable
Reading User Input
Via command line arguments and prompting users for input
Curl Post Request
Use cURL to send data to a server
Upload Files With curl
Learn how to upload a file to FTP, SFTP servers, Artifactory, and AWS S3 using the curl command.
How To Copy A Directory In Linux
Learn how to copy directories and their content in Linux using the cp command with options like -r for recursive copying, -i for interactive mode, and -a for preserving attributes.
Create Groups In Linux
Learn how to manually and automatically create and list groups in Linux.
How to Check the Size of Folders in Linux
Learn how to output the size of directories and subdirectories in a human-readable format in Linux and macOS using the du command.
Count Files in Linux
Learn how to count files and folders contained in directories and subdirectories in Linux using the ls, find, and wc commands.
List Open Ports in Linux
Learn how to output the list of open TCP and UDP ports in Linux, as well as their IP addresses and ports using the netstat command.
Format Command Output In Linux
Learn how to filter and format the content of files and the output of commands in Linux using the awk command.
Create Directories Recursively With mkdir
Learn how to recursively create nested directories using the mkdir command, Bash scripts, and Python scripts.
Remover Users in Linux
Learn how to remove local and remote user accounts and associated groups and files in Linux using the userdel and deluser commands.