Tuesday, February 19, 2013

Crontab

With cron you can execute scripts or commands based on a schedule.
For example, if I want to run a script every 5 minutes, I have to do as follows: 

crontab -e
This will bring you in the edit mode, than we specify that a script must be executed every 5 min.
*/5 * * * * /home/geek/myscript.sh

From now on, every 5 min. the script myscript.sh will be executed.
Crontab works as follows, you have to tell it according to a certain format what time interval to execute a command.
The format is as follows:
minutes (0-59)    hour (0-23 0=midnight)    day (1-31)    month (1-12)    weekday (0-6 0=Sunday)
So the following will run at 01:15 every Sunday.
15 1 * * 0 /usr/bin/date

Another one is to run a script every 30 min. on every day.
*/30 * * * * movelogfiles.sh
or
0,30 * * * * movelogfiles.sh


To remove the 'cronjob' we issue the following command:
crontab -r

To list the cronjobs (so you can see what jobs it has):
crontab -l

No comments:

Post a Comment

NSNotification example