Easily Automate and Schedule Routine Tasks with CRON

Automation is a vital tool. It allows us to identify tasks that happen on a predictable schedule, define the process by which the tasks are done, and then remove ourselves from the burden of executing the tasks on that pre-defined and predictable schedule going forward. Automation is commonly associated with machines performing physical tasks, but the virtual world is another area where automation can really shine — and one of the tools for doing that is cron.

Cron is a command-line utility that acts as a job scheduler and allows you to schedule repetitive tasks. It can be used for anything — sending a weekly orders summary to a third-party service, scheduling an online course to publish at a future date, or just checking the weather at a certain time every day and sending yourself an update. So how can you use cron?

Cron uses a simple 5-character pattern that allows you to define any time at any scheduled interval. A series of 5 asterisks represent the minute of the hour (0 – 59), the hour of the day (0 – 23), the day of the month (1 – 31), the month itself (1 – 12), and the day of the week (0 – 6).

With cron, you first define the schedule with a cron expression and then follow it with any valid command line expression(s). Now, let’s go through some examples of defining cron expressions using crontab guru — a site that converts cron expressions to their textual equivalent.

Cron can be as vague or as specific as you need it to be. You can do something simple like executing a command at 9:30 AM every day:

30 9 * * * at 9:30

Or you can specify further, by choosing the day and month.

30 9 1 1 * at 09:30 on day-of-month 1 in January
There are 4 main characters that can be used in combination with numbers to create a cron schedule expression.

Table of pattern specifiers. Asterisk * equals any value. Comma , equals value list separator. Dash - equals range of values. Forward slash / equals steps values.

These additional specifiers open up the door to define the same cron expression in a number of different ways.

Using the value list separator:

0,15,30,45 9 * * * at minute 0, 15, 30, and 45 past hour 9

Or using step values:

*/15 9 * * * at every 15th minute past hour 9

And then you can even use a range of hours:

*/15 9-11 * * * at every 15th minute past every hour from 9 through 11

These are just a few examples of possible cron expressions, but these patterns are tools we can use to define virtually any scheduled interval. With just some numbers and a handful of pattern specifiers, we can fire off any command at any time. Cron can be used for something as simple as sending a message at a certain time, or for something far more complex, such as running a script that automates sending all of your store’s orders to a third-party service. Regardless of what you’re trying to do, the process of defining the schedule with cron is the same. How the scheduling power of cron is utilized is up to the individual needs of the person using it, but the power it offers is universal. For more help automating tasks for your specific business, contact the experts at Hall.

See how Hall can help increase your demand.