crontab -e --> edits the crontab file so you can make entries of scheduled jobs to run.
crontab -l --> lists the crontab file, its like running a "cat" command on a text file.
crontab -r --> removes the crontab file. The most dangerous, make sure you have a backup of your crontab file before you run this command even be it for test reasons.
One has got to be very careful in dealing with the -r flag. if you inadvertently type -r for -e and hit enter, the next thing you know is your crontab file is gone. since E and R are located next to each other on a regular QWERTY keyboard and if you are not really good with the finger positioning of the keyboard, this is sure a nightmare.
This had once happened with me since I am not good at the finger positioning myself on a QWERTY keyboard.It is only after hitting the return key that I realized, I typed the wrong command. But a backup of the crontab should save the day, like it did to me.
Its always a good practice to have a backup of the crontab file. Use the command "crontab -l" to backup the crontab file as shown below.
00 01 * * * crontab -l > /export/oracle/crontab_backup.txt
The above line takes a backup of the crontab at 01:00 hours everyday.
Now, to restore a blank crontab, all you need to do is run the following command. sometimes this might require a bounce of the cron daemon
crontab < /export/oracle/crontab_backup.txt
Let's discuss about the conventions of making entries in a crontab file. There are six fields for an entry in a crontab, below is a depiction which explains about the fields. Fields are seperated by a white space or a tab.
* * * * * COMMAND_OR_SCRIPT_LOCATION
--------------------------------------------------------------------
| | | | | |_ Command or script location
| | | | |
| | | | |___ Day_Of_Week (0 - 6) (0=Sun, 1=Mon, 2=Tue,3=Wed,
| | | | 4=Thu, 5=Fri, 6=Sat)
| | | |_____ Month_Of_Year (1 - 12)
| | |
| | |_______ Day_Of_Month (1 - 31)
| |
| |_________ Hour (0 - 23)
|
|___________ Minutes (0 - 59)
No comments:
Post a Comment