Repeating tasks with crontab
Archive - Originally posted on "The Horse's Mouth" - 2005-12-27 14:37:34 - Graham EllisSome things happen every day - or twice a day, or weekly ... in the background behind our web site - things like the rotation of log files, generation of reports and copying the Opentalk Forum into archives. We don't trigger these things manually!
On Unix and Linux systems, your crontab lets you set up jobs to be run in a regular (or irregular) pattern according to day of month, month, hour, minute and day of week. Simply use the command crontab -e on your server to edit your crontab, and insert one line per job required. For example:
11 13 * 3-9 * cp /home/wellho/summerpm.jpg /home/wellho/public_html/iotd.jpg
would copy an image called "summerpm" to an image called "iotd" at 11 minutes after the hour of 13, every day on the month, March to September only, every day of the week and:
1 2 * * 6 cp /home/wellho/weekend.jpg /home/wellho/public_html/iotd.jpg
would copy the image called weekend at one minute after 2 every Saturday morning.
Not every web space provider allows you to run crontab jobs, but if it's there for you, it's an invaluable tool. Just remember to never type in the word "crontab" on its own as it deletes all your existing jobs and replaces them with whatever you care to type at the keyboard!