How to Set an Hourly Cron in Ubuntu Server Tips, Tricks and Tutorials 15 APR 2015

Just a quick reminder to myself as to how to set an hourly cron on an Ubuntu Server instance using the standard Crontab mechanism (use crontab -e to edit your crontab).

hourly - clock turning 12

Now “* */1 * * * command.sh” (similar to how you would do one for every couple of minutes) may look very tempting at first glance, but this is in fact wrong. While what you are doing here does indeed say to run every hour (*/1), the first * means that it needs to run every minute. So what you are basically doing is runing the command at the start of each minute for each and every hour.

Not exactly what we’re looking for.

Instead, the correct way would be to simply specify the minute to run at – so say 0 to indicate the top of the hour. So a correct string to achieve a scheduled task that runs once an hour would be:

0 */1 * * * command.sh

A small, but significant point to remember then!

(Also, useful to remember that if you want to run your command with administrator privileges, you need to edit your crontab using sudo crontab -e. This crontab is separate for one edited without the sudo command!)

Related Link: https://help.ubuntu.com/community/CronHowto

Related Posts:

About Craig Lotter

Software developer, husband and dad to two little girls. Writer behind An Exploring South African. I don’t have time for myself any more.