blogblog SyKoHPaTh

Set up a cron job

A cron job is a way to "automatically" run a script at a specific interval. It's not too difficult to setup.

1) From terminal, edit the cron table:
crontab -e
2) That starts a VI session to enter lines. Press i to start edit mode.
3) Add the job in the following format:
So, an example to run a script every weekday (1-5) at midnight (0:0), every month (*):
0 0 * * 1-5 /home/sykohpath/scripts/
4) When finished, press ESC, then : to bring up the prompt, and finally save and quit by typing x

Note: An email is sent to the useracount that executes the cron job, so it's a great way to get confirmation that the script ran automatically or not. However, this can get annoying, so to disable it, add the following at the end of the cron job line that emails are not desired:
/dev/null 2>&1
(write output to null).

Reference: Crontab Quick Reference

linux, reference