Visit Our UNIX and Linux User Community


Auto enable/disable cron job


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Auto enable/disable cron job
# 1  
Old 12-09-2009
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
# 2  
Old 12-09-2009
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.
# 3  
Old 12-09-2009
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.
# 4  
Old 12-09-2009
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.
Code:
crontab -e

and change the time stamps for the particular cron job that you want.
Regards.
# 5  
Old 12-09-2009
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.
# 6  
Old 12-09-2009
Quote:
Originally Posted by steadyonabix
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

Previous Thread | Next Thread
Test Your Knowledge in Computers #285
Difficulty: Easy
AIX was the first operating system to have a proc file system.
True or False?

10 More Discussions You Might Find Interesting

1. Infrastructure Monitoring

OID to disable/enable printing

Hi @ all, we are a non-profit educational organisation. Now my company wants to disable printers, when a room is not used. I do a lot monitoring, using snmp. So I had the idea of disabling and enabling the printers by using snmp. After searching for hours, I only found some status-objects (ro)... (1 Reply)
Discussion started by: karls0
1 Replies

2. HP-UX

FTP service Enable/Disable

hi everybody, I can easily enable /disable the FTP service from SAM, how can I do this via command line? using inetd? how? cheers, messi (1 Reply)
Discussion started by: messi777
1 Replies

3. UNIX for Dummies Questions & Answers

Enable and disable the auto mount

How to enable and disable the auto mount option for USB devices.? (3 Replies)
Discussion started by: ungalnanban
3 Replies

4. UNIX for Dummies Questions & Answers

crontab: disable/enable

since i don't have root access, i have been doing: crontab -l > /tmp/username.crontab crontab -r vi /tmp/username.crontab and copy page crontab -e, and paste sometimes, /tmp/username.crontab has more than 1 page, so i have to copy twice. how do i copy all contents from... (2 Replies)
Discussion started by: tjmannonline
2 Replies

5. Shell Programming and Scripting

How to disable Enable/Disable Tab Key

Hi All, I have bash script, so what is sintax script in bash for Enable and Disable Tab Key. Thanks for your help.:( Thanks, Rico (1 Reply)
Discussion started by: carnegiex
1 Replies

6. UNIX for Dummies Questions & Answers

disable cron job

Hi all, I am not the unix person but have to disable cron job on the server I typed crontab -l to list the job there is one job then i tried crontab -e and got one result 100 ( i do not know what that means) how can i disable the job to run i want to disable the job. Please show me... (3 Replies)
Discussion started by: patdev
3 Replies

7. Solaris

SSH enable, Telnet disable ...

Hi... How do I enable SSH and disable telnet.. Also - is there anything special I need to do to ensure that a new user can use ssh and su but not telnet? Adel (15 Replies)
Discussion started by: ArabOracle.com
15 Replies

8. Solaris

Cron Job -- auto start process when it dies

I would like to setup a Cron job to check weather X process is running or not. if it is not running then start that X process with a log message.... can any one help writing a script? thanks (3 Replies)
Discussion started by: chandravadrevu
3 Replies

9. UNIX for Dummies Questions & Answers

disable cron job

hi i got to shut down my server for the new year day. i am required to disable all cronjob temporarily. what is the command to do so? after start up the server will the cron job run itself automatically or i gotta restart all again? (8 Replies)
Discussion started by: legato
8 Replies

10. Linux

Enable and disable ttyS0

I have a modem connect it to ttyS0 , in unix sco i know i can disable and enable the port , how can i do this , is there a command that will allow me to do this. **** I'm running Redhat 9 *****External Usrobotics 56k Thanks a lot guys (1 Reply)
Discussion started by: josramon
1 Replies

Featured Tech Videos