How to run cron every hour
Philip Wilkinson
Software Engineer, Amazon
Published: 2/1/2024
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.sh
Run in Warp
Other 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)
* * * * *
Run in Warp
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!
Written by
Philip Wilkinson
Software Engineer, Amazon
Filed Under
Related Articles
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.
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.
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.
Linux Chmod Command
Understand how to use chmod to change the permissions of files and directories. See examples with various chmod options.
POST JSON Data With Curl
How to send valid HTTP POST requests with JSON data payloads using the curl command and how to avoid common syntax pitfalls. Also, how to solve the HTTP 405 error code.
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 Groups In Linux
Learn how to manually and automatically create and list groups in Linux.
Switch Users In Linux
Learn how to switch between users, log in as another user, and execute commands as another user in Linux.
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.
Delete Files In Linux
Learn how to selectively delete files in Linux based on patterns and properties using the rm command.
Find Files In Linux
Learn how to find and filter files in Linux by owner, size, date, type and content using the find command.
Copy Files In Linux
Learn how to safely and recursively copy one or more files locally and remotely in Linux using the cp and scp command.