Enable/Disable tasks in Crontab by Bash/Shell
SERVERNUM=$1
To enable:
crontab -l | sed "/^#.*Server $SERVERNUM check/s/^#//" | crontab -
To disable:
crontab -l | sed "/^[^#].*Server $SERVERNUM check/s/^/#/" | crontab -
Transcript:
barmar@dev$ crontab -l*/1 * * * * Server 1 check*/1 * * * * Server 2 check*/1 * * * * Server 3 checkbarmar@dev$ crontab -l | sed '/^[^#].*Server 1 check/s/^/#/' | crontab -barmar@dev$ crontab -l#*/1 * * * * Server 1 check*/1 * * * * Server 2 check*/1 * * * * Server 3 checkbarmar@dev$ crontab -l | sed '/^#.*Server 1 check/s/^#//' | crontab -barmar@dev$ crontab -l*/1 * * * * Server 1 check*/1 * * * * Server 2 check*/1 * * * * Server 3 check
this is a variant, I use a cronjob that loads it self every night. I just edit a file and it gets reloaded at 10pm everynight. You could make the reload happen more often. I keep a directory of files for each of nodes. The trick is make sure that nobody comments out the reload line.
0 22 * * * crontab /home/ME/cron_files/NODE