Setting up Cron Job Using crontab:
Step 1:open a Terminal windows (Command line) in Linux.
Step 2:the Following is a list of cron directories:/etc/cron.hourly
/etc/cron.daily
/etc/cron.weekly/etc/cron.monthly
Copy your shell script ' script.sh ' or ' script ' into one of the directories above. If you are need to run the script hourly, place your script file in the "cron.hourly" folder. For daily, where it inside the "cron.daily" and so forth.
Step 3:give The shell script the correct permission. For example, if the script is called "script.sh", set permission as follows:
Cd/etc/cron.daily/chmod 755 script.sh
Step 4:add The new cron job to crontab:
Crontab–e
This is opens VI editor for you. Create the cron command using the following syntax:
1.2.3.4.5.6.
More
The number of minutes after the hour (0 to 59)
The hour in military time (hour) format (0 to) the "Day of" month (1 to 31)
The month (1 to 12)
The day of the week (0 or 7 are Sun, or use name) the command to run
Graphically they would look like this:
* * * * * Command to be executed-----| | | |
| |
| |
| |
| +-----------Hour (0-23)
+-------------Min (0-59)
| | +-----Day of Week (0-7)
| +-------Month (1-12)
+---------Day of Month (1-31)
An example command would is "0 0 * * */etc/cron.daily/script.sh". Thiswould mean that shell script would exactly execute at midnight Everynight.
To save the changes to the crontab so you just made, hit ESC key, Andthen type:w and followed to exit.
To list existing cron jobs:
Crontab–l
To remove an existing cron job:
Enter:crontab–e
Delete the line that contains your cron job hitesc>:w>:q