TNick.github.io

home

Cron jobs

28 Jun 2014

Overview

Wikipedia The software utility Cron is a time-based job scheduler in Unix-like computer operating systems. Cron jobs are created using the command line program called crontab.

usage:  crontab [-u user] file
    crontab [ -u user ] [ -i ] { -e | -l | -r }
        (default operation is replace, per 1003.2)
    -e  (edit user's crontab)
    -l  (list user's crontab)
    -r  (delete user's crontab)
    -i  (prompt before deleting user's crontab)

To create a new one call it like so:

crontab "path-to-file"

The format of a crontab schedule (the text file) consists of 6 fields:

minute hour day month day-of-week command-line-to-execute

To run a command once a day, at 8:15 PM use:

15 8 * * * echo "Its 8:15 PM"

To run a command once an hour use:

0 * * * * echo "ello" >/dev/null

To run a command once every two hours use:

0 */2 * * * echo "ello" >/dev/null

To run a command at 8:15 and 16:15 use:

15 8,16 * * * echo "ello" >/dev/null

Listing

To list running jobs use

crontab -l

Editing

Rather than creating a file for every command one can edit the list of jobs using:

crontab -e

Removing

Remove all jobs:

crontab -r

Resources

Tagged with walkthrough

"Any sufficiently advanced troll is indistinguishable from a genuine kook." Alan Morgan