How to create a cron job using script without editor
APPLIES TO : cron job modification
GOAL : This document explains how to add any cronjobs by using a script without open the corntab in editor.
SOLUTION : Create a script with like below, modify the cron job as per your environment requirement, execute the script to perform the modification.
#!/usr/bin/ksh
#write out current crontab
crontab -l > /tmp/mycron
#echo new cron into cron file
echo '* * * * * uname >> /tmp/cron.out' >> /tmp/mycron
echo '* * * * * date >> /tmp/cron.out1' >> /tmp/mycron
#install new cron file
crontab /tmp/mycron
rm /tmp/mycron
Cron line explanation :
~Judi~
APPLIES TO : cron job modification
GOAL : This document explains how to add any cronjobs by using a script without open the corntab in editor.
SOLUTION : Create a script with like below, modify the cron job as per your environment requirement, execute the script to perform the modification.
#!/usr/bin/ksh
#write out current crontab
crontab -l > /tmp/mycron
#echo new cron into cron file
echo '* * * * * uname >> /tmp/cron.out' >> /tmp/mycron
echo '* * * * * date >> /tmp/cron.out1' >> /tmp/mycron
#install new cron file
crontab /tmp/mycron
rm /tmp/mycron
Cron line explanation :
1. The number of minutes after the hour (0 to 59)
2. The hour in military time (24 hour) format (0 to 23)
3. The day of the month (1 to 31)
4. The month (1 to 12)
5. The day of the week(0 or 7 is Sun, or use name)
6. The command to be executed.
* * * * * "command to be executed"
- - - - -
| | | | |
| | | | ----- Day of week (0 - 7) (Sunday=0 or 7)
| | | ------- Month (1 - 12)
| | --------- Day of month (1 - 31)
| ----------- Hour (0 - 23)
------------- Minute (0 - 59)
~Judi~
No comments:
Post a Comment