Issues:
Cron jobs are running everyday at 8PM to hot backup database, archivelog, and some other files.
Sometimes crontab scheduled backups need to be suspended for some other tasks randomly but doesn't happen all the time.
Objective:
I need to create simple script or command ( example : stop_cron, start_cron) that will suspend cronjob for that particular day.
Purpose is that we have "Operator" ( no root privilege, and no dba / unix background ) that need to run simple command to stop or start certain cront jobs out of 20+ job scheduled in crontab.
I am wondering is there way to merge sh script into backup script so when "stop_cron" command is executed then only that particular crontab will be skipped even though schedule fired off the job from crontab.
The operators would then have a script that would create/remove the lock file (where they have permissions to write). You could also implement that lock file logic into the backup script.
The danger in all of this is that if someone forgets to re-enable the backup script, backups won't be performed. I suppose you could also implement another job that would remove any lock file older than say 3 days.
One way is to use a control file for any "state" oriented scripts.
Create a directory in /var/tmp called "croncontrol"
Create a script called "disable" that accepts variables depending on the cronjob name (backup, reportmailer, etc).
This script will touch /var/tmp/croncontrol/backup or /var/tmp/reportmailer, etc.
Create a wrapper for your cron script (or add a line to the existing cron script) that checks for the file /var/tmp/croncontrol/backup (or mailer or whaterver). If the file exists, exit and do not run (although I'd recommend that it mail out that the script is not being run). If the file does not exist, proceed with the normal script function.
To enable the cron scripts to run again, write a simple script that accepts the same variables to rm the 'touched' file in /var/tmp/croncontrol.
I'd probably do something like avronius mentioned. Pseudo code for disable:
Check $0 for name of script to be enable or disable
Check $1 for the backup to disable/enable
Case the backup in
full - if script name is enable, remove full file
if script name is disable, touch full file
home_dirs - if script name is enable, remove home_dirs file
if script name is disable, touch home_dirs file
...etc, etc...
Once disable script is written, create an enable soft link that points to the disable script so you can use the same script for both purposes.
Sorry for the confusion, but this is not how the manageCron script works.
The command takes two arguments:
The first argument is the enable/disable flag.
You can use -d or --d or -disable or --disable to create a file.
You can use -e or --e or -enable or --enable to delete a file.
The second argument is the name of the file that you want created - this is the name of the file that cron will look for before starting the process that you are managing.