Shell Script : Auto Enable/Disable Specific Cronjob

Shell Script : Auto Enable/Disable Specific Cronjob

What is Cronjob ?
A cron job is a scheduled task that is executed by the system at a specified time/date.

Sometimes we want to perform some task during specific time(Ex: During production Hours), and once the production time completes, we will be disabling cronjob. this requires manual work.The above manual work, can be automated with this script.

Create two scripts,

Below are both the scripts with cronjob details,


crontab -l | sed ‘/^#.*^#//’ | crontab –
crontab -l | sed ‘/^[^#].*^/#/’ | crontab –



In the above image we can see that after running
The script in the cron is uncommented and after running the script is commented again.

Now add scripts to desired time in cronjob.
9 * * * * /home/cronjob/ (This will enable @9)
23 * * * * /home/cronjob/ (This will disable @23)

Enjoy, just now you have automated your task!!!!.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>