Thursday, January 03, 2008

how to: use cron

ok, now that i really know how to use the cron i should blog it incase i forget

this assumes you have nothing in your cron / or your crontab is in sync with hostname.cron because you always use this method to modify the crontab.

0. run crontab -l to make sure your crontab is empty, if its not, paste what it has to the bottom of the file you make in step 1

1. make a file called hostname. cron and add this into the top of it for later:
#########################################
# #
# Cron file for [username] #
# #
#########################################
# min hour dom month dow usr cmd
# use '*' as skipped element

2. add your stuff to it, here is a better explanation on what to add:
01 * * * * echo "This command is run at one min past every hour"
17 8 * * * echo "This command is run daily at 8:17 am"
17 20 * * * echo "This command is run daily at 8:17 pm"
00 4 * * 0 echo "This command is run at 4 am every Sunday"
* 4 * * Sun echo "So is this"
42 4 1 * * echo "This command is run 4:42 am every 1st of the month"
01 * 19 07 * echo "This command is run hourly on the 19th of July"

3. save your file.

4. run this:
crontab < hostname.cron

done!

useful info happily stolen from here: http://www.unixgeeks.org/security/newbie/unix/cron-1.html

No comments:

Post a Comment