What is a Cron job?

Cron Jobs are scheduled jobs that are performed either at the user or root level of the system. For Windows admins out there think of this as the same equivalent as Task Scheduler.

Creating A Cron Job

To make a cron job as the user currently logged in you just have to type in the following command:

crontab -e

To make a cron job that runs as root all you have to do is type in sudo before the command:

sudo crontab -e

When you start making a cron job for the first time it’ll ask you what text editor you want to use (eg. vim or nano). For anyone that has never used either I recommend using nano as its easier to use for beginners.

CronJob formats

When you create a cron job for the first time the crontab file will be blank except for the default notes, the cron tab will be in the format of 5 numeric values follow by a command or a script. You also must be mindful of the system time that you are making the scripts on.

* * * * * /path/to/script.sh

Cron will check every minute to see if it needs to run a cron job, the table below is the format of how times are specified:

|------------Minute (Valid Values: 0-59)
| |----------Hour (Valid Values: 0-23, 0=Midnight)
| | |--------Day of Month (Valid Values: 1-31)
| | | |------Month (Valid Values: 1-12)
| | | | |----Day of Week (Valid Values: 0-6, 0=Sunday)
* * * * * /path/to/script.sh

Time Examples

To run a script every minute indefinitely:

* * * * * /path/to/script-or-command

To run a script every 10 minutes:

*/10 * * * * /path/to/script-or-command

To run a script every Wednesday at 3AM

0 3 * * 3 /path/to/script-or-command

More Friendly Timers

Cron also offers more friendly timers to start scripts if the table above is confusing.

Friendly Version Uses
@reboot Starts a script at reboot/boot
@yearly Runs once a year (Same as 0 0 1 1 * )
@annually same as @yearly
@monthly Run once a month (Same as 0 0 1 * * )
@weekly Run once a week (Same as 0 0 * * 0 )
@daily Run once a day (Same as 0 0 * * * )
@midnight Same as @daily
@Hourly Run once an hour (Same as 0 * * * * )

Examples:

@reboot /path/to/script-or-command

<
Previous Post
Where Windows Command? Yes, Right Here!
>
Next Post
Verbose Logon, Logoff And Startup Messages