Scheduled Tasks on Linux

9 02 2010

To schedule a task on Linux, crontab is what we need to know. On CentOS, /etc/crontab is cron configuration file. The pattern is not different from any linux distro.
# run-parts
01 * * * * root run-parts /etc/cron.hourly
02 4 * * * root run-parts /etc/cron.daily
22 4 * * 0 root run-parts /etc/cron.weekly
42 4 1 * * root run-parts /etc/cron.monthly

If you encounter a problem, some variables like SHELL and PATH should be considered. For the pattern, it follows:
minute(0-59) hour(0-23) day(1-31) month(1-12) dayofweek(0-7, yes, 0=7=Sunday) command

Schedule a task

Make sure cron is running by
/sbin/service crond status
> crond (pid 6472) is running...

If not, turn the service on by
/etc/init.d/crond start
To add a task
crontab -e
Then add a task following the pattern mentioned above.
Well, the crontab editor is VI.
To view our scheduled tasks
crontab -l
Restart the service after scheduling the task.
/etc/init.d/crond restart
More details of setting a task with crontab can be read here.



Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: