Auto enable/disable cron job

Hi all,

Does anyone know if it is possible to enable/disable a cron job within a script?

I currently have a cron job which runs every minute but now it seems that sometimes I would like to turn this job off if a condition is met. I would then like to re-enable the job at a later date.

Any ideas?

Thanks

You can edit the file for the specific crontab, which is usually somewhere under /var/spool/cron* depending on type of OS.
After the alteration reload/restart the cron demon according to your OS/installation.

You can do that, though you might want to look at using "at" instead. When faced with a script that decides for itself when it will next execute, I find "at" a little more straightforward than than translating to a cron entry.

hello
you stop or kill the cron job. or remove it from the sysV scripts aka /etc/init.d/ or /etc/rc.d/init.d
make them not to start in the runlevel you boot in like replacing for e.g.
S450mysqld to K450mysqld for mysqld to not start at that runlevel 5.in /etc/rc.d/rc5.d.
later you can start them by doing the opposite.
There are many ways to do it.
Otherwise if you are bothered by the 1 min gap why dont you increase the gap by editing the crontab entry in the crontable.

crontab -e

and change the time stamps for the particular cron job that you want.
Regards.

I have seen this implimented with what were called "jobfiles" by the scripts in question. This was to enable testers to turn off each others cron jobs without having the necessary UNIX permissions. It worked like this: -

1) Cron job starts and looks for a "jobfile".
2) If found it looks for a command such as "Skip". This would cause it to clear its own crontab and exit.

Other commands such as "suspend [minutes]" or whatever can be implemented in the same way.

I have done similar to this by having the script that executes from cron check for the existence of a specific file before executing, thus effectively giving you an on/off switch