Wednesday, October 12, 2011

Crontab tutorials

Crontab

Commands
#crontab -e Edit your crontab file, or create one if it doesn't already exist.
#crontab -l Display your crontab file.
#crontab -r Remove your crontab file.
#crontab -v Display the last time you edited your crontab file. (This option is only available on a few systems.)

File
#crontab -e
A crontab file has five fields for specifying day , date and time followed by the command to be run at that interval.
* * * * * command to be executed
- - - - -
| | | | |
| | | | +----- day of week (0 - 6) (Sunday=0)
| | | +------- month (1 - 12)
| | +--------- day of month (1 - 31)
| +----------- hour (0 - 23)
+------------- min (0 - 59)

• * in the value field above means all legal values as in braces for that column.

Example:-
Q1. How can I remove all log messages at 6:30 PM daily?
Ans. 30 18 * * * rm /home/user/tmp/*
Q2. How can I remove all log messages at 6:30 only on (Sat- Sun)?
Ans. 30 18 * * 6-7 rm /home/user/tmp/*
Q3. How can I remove all log messages on 1st, 10th and 15th of month Oct.?
Ans. 30 18 1,10,15 10 * rm /home/user/tmp/*
Q4. How can I remove all log messages after every 15 mins?
Ans. 15,30,45,59 * * * * rm /home/user/tmp/*

No comments:

Post a Comment