Friday, 7 October 2011

Setting up cron

Setting up recurring tasks in a Unix-like / Linux environment is done via a program / mechanism called cron. You edit it (usually) using vi, and you put in variables of when you are supposed to run jobs - similar to a scheduler. The order of those fields is something I always seem to forget, so here they are (to remind me to populate the top of the cron files):

# Minute Hour Day of Month Month Day of Week Command
# (0-59) (0-23) (1-31) (1-12 or Jan-Dec) (0-6 or Sun-Sat)

As an example:

0 2 12 * 0,6 /usr/bin/find /stuff

Putting those comments at the top of every cron file should be enough for others to figure out what is being done. To display cron jobs, type (without the "$"):

$ crontab -l

To edit cron jobs, type:

$ crontab -e

Remember to use vi commands when editing. The Gentoo Linux vi page is a really good start, or you can just go directly to the vi "cheat sheet".

No comments:

Post a Comment