Monday, September 1, 2008

Linux - Cron Scheduler Configuration

cron is the task scheduler in Linux. It basically runs the given command on a specific time/interval. Any linux user can schedule the task for this cron daemon. cron is a daemon, because it runs as part of all other system services. If this service doesn't run in background, scheduling will not workout. To run the cron daemon as a system service, you have to open Services UI from System Administration Menu from GNOME X-Window UI, and then choose this cron daemon to run as a service. Or else you can use the ntsysv command, and then select cron to as system service. You may required to restart the system once.

#ntsysv #UI will open, there you can select services to run when the system starts

To schedule the command, you have use the crontab -e. It will open a vi editor, there you can see the already scheduled tasks, if nothing got scheduled before, an empty vi editor will open. Following is the format by which the task can be scheduled.

$crontab -e
30 17 1 * * ~/backup/backupscript
~
~
~

:wq #Save and Quit

There are five asterisks (*) separated by any whitespace, and then the task to run.

In place of 1st Asterisk - Minutes 0 - 59 can be given
In place of 2nd Asterisk - Hour 0 - 23 can be given
In place of 3rd Asterisk - Date 1 - 31 can be given
In place of 4th Asterisk - Month 1 - 12 can be given
In place of 5th Asterisk - Day of the week 0 - 6 can be given

So as per the configuration backup script will run by evening 5:30 on first of every Month.

If you are the superuser and you want to configure the cron job for user say 'jacob'. You can use the -u option.

#crontab -e -u jacob #Edit cron con configuration of the user jacob

With -l option you can get the list of task scheduled.

$crontab -l
30 23 1 * * ~/backup/backupscript

--
Anand
anand.sadasivam@googlemail.com

No comments: