FlyZhy.Org logo Projects - Cron - Crontab

Before
HowTo
Basic
flyzhycron
After
References

Cron is the name of program that enables unix users to execute commands or scripts (groups of commands) automatically at a specified time/date. I use Cron to do some backup or upload stuffs at a specified time.

Before

HowTo

Basic

It's very easy to use cron, and the command we use is crontab, you can use #man crontab to know more about it, but the basic usage is:

crontab [-u user] -e -l -r
-u: user
-e: edit crontab file
-l: list crontab file
-r: remove crontab file

The step to set up your own crontab file are:

  1. create a new crontab file with usercron as its name which user is the user name of the Cron you want to set.
  2. edit the usercron you create according to the following format1:
    # Format and Range:
    # minute hour day month week command[script]
    # 1~59 1~23 1~31 1~12 0~6 command[script]
    #
    #(put your own initials here) echo the date to the console every
    #15 minutes between 6pm and 6am
    0,15,30,45 18-06 * * * /bin/echo 'date' > /dev/console
    
  1. cron as the user:
    #su user
    #crontab usercron
    
  2. verify the crontab file. After crontab it will make a copy of the crontab file in /var/spool/cron/crontab/ with user as its name, check it out then.

flyzhycron

# crontab
# cron
# format: minute hour day month week command
# range:   1~59  1~23 1~31 1~12 0~6
# flyzhycron
# by Haiyong Zheng
# website: http://www.flyzhy.org
#
# backup bbs Data of Dreamers.Com.Cn
28 14 * * * /home/flyzhy/bin/backup-dreamers-bbs.sh
#
# upload bookmarks from my firefox automatically
28 15 * * * /home/flyzhy/bin/upload-bookmarks.sh
#
# backup config files from the system
28 20 * * * /home/flyzhy/bin/backup-config-files.sh

After

Wait for something happen amazing now. ^_^

top

References


1. Notice that the command[script] must be the absolute position like /bin/echo but not just echo.