Monday, 7 September 2020

Enable or Disable Cron jobs Using Single Command

 A quick one, DBAs frequently need to disable/enable cron jobs. This can be often a time killer, so here are three commands to make life easier.

Only affects cron of current logged on user:

#-- Take a fresh backup of current cronjobs for reference
crontab -l > /tmp/cron.bkp

#-- Disable Cronjobs
crontab -l | sed 's/^/#/g' > /tmp/cron.edit; crontab /tmp/cron.edit; crontab -l

#-- Enable Jobs
crontab -l | sed 's/^#//g' > /tmp/cron.edit; crontab /tmp/cron.edit; crontab -l

Cheers!
Anurag

No comments:

Post a Comment