A webmaster’s day may involve doing a series of repeated tasks, like checking servers’ vital statistics, rotating server access logs, gathering visitor data and what-nots. To keep things simple and in control it is essential to use cron to manage these tasks. What it does is this daemon will perform tasks according to the times specified. To start assigning cron jobs to linux systems you enter crontab -e. Usually the format is like below:
The 5 asterisks specifies in order the minute, hour, day of month, month, and day of week of which the command will be run. So if I want to run a script that rotates server logs on every sunday at 3:30am then I’ll make a call like this:
The latter part of the line specifies that I want all the script output and error messages to be logged into logs.log, which will be a piece of useful information when things go wrong.
What about commands that requires to be run more frequently? Say we need to run a script that checks a server’s well-being every 3 hours, you can set the cron job up like this:
Alternatively, you can also set it up like this:
* */3 * * * /path/check_well_being.sh >> wellbeing.log 2>&1
The only difference from these two ways is that cron will only make sure the command is run every 3 hours, but not necessarily on 3, 6, 9, and 12 o’clocks of the day.
When you finish editing, save the cron job, and check it by entering crontab -l, if everything is right then the cron jobs will start running those commands by itself.