Thursday, August 30, 2012

Scheduling a task using 'crontab'

Suppose you want to schedule a task in Linux and you want it to run periodically, then 'crontab' command is what you are looking for. I've just learned this, so I still don't know much details about it, but following is what I've learnt.

Syntax:

To create a 'crontab' entry,

                      #crontab -e 

To get a list of crontab entries you have,

                      #crontab -l

The way that you should edit the crontab file, (vi editor will be used)

                       'min' 'hr' 'day' 'mon' 'day-of-week' <command>

min - minute of the hour.(ex: 15)
hr - hour of the day(ex: 3)
day - day of the month(ex: 29)
mon - month of the year(ex: 5)
day-of-week - As name implies.(ex: 0)   0 is sunday.
command - This is the command you want to execute.


Example:

Following will write "Crontab is working" to 'abc.log' file in /home/pradeepa directory. (use your username instead of pradeepa) 

                * * * * * echo "Crontab is working" >> /home/pradeepa/abc.log

And the star mark is used to tell "every".

There is a great article on crontab in wikipedia,


This is just an introduction to 'crontab', what you can do from this is up-to your innovative mind.

Cheers.

No comments:

Post a Comment