klenwell information services : LinuxCron

Cron

return to DevLinux

Basic Commands

# load a file as user's cron
$ crontab ~/mycrons/master.cron

# list user's cron
$ crontab -l


Syntax

Notes


Basic cron file line syntax

# cron (run every minute)
# M H DM MO DW      SCRIPT
*  *  *  *  *       touch /tmp/klenwell_test_cron

# cron.d (run every 15 minutes every other day)
# M H DM MO DW      USER        SCRIPT
*/15 *  *  *  */2   klenwell    touch /tmp/cron_test.txt

Cron Fields:
M : Minutes
H : Hours
DM : Day of Month
MO : Month
DW : Day of Week

cron.d

To enable a cron file through the cron.d directory, create a symbolic link. For example:
$ sudo ln -s ~/mycrons/crond-test.cron /etc/cron.d/crond-test


Sample cron.d File

# cron.d file
# to activate, link to /etc/cron.d: [sudo] ln -s [path/]fname.cron /etc/cron.d/link_name

# +---------------- minute (0 - 59)
# |  +------------- hour (0 - 23)
# |  |  +---------- day of month (1 - 31)
# |  |  |  +------- month (1 - 12)
# |  |  |  |  +---- day of week (0 - 6) (Sunday=0 or 7)
# |  |  |  |  |
# M  H DM MO DW     USER        SCRIPT
*  *  *  *  *       klenwell    touch /tmp/crontest.txt


References

Intro to Cron (unixgeeks.org)