1820100 Members
3427 Online
109608 Solutions
New Discussion юеВ

stopping cron

 
Phil Corchary
Advisor

stopping cron

I need to script cold-backups while at run-level 3. One of the first things I want to do is make sure that no cron jobs run during the backup. How?

Just stopping cron using the init script won't work, as it respawns. Should I move the crontabs?

Suggestions - or am I going about this wrong?
99% of the game is half mental. - Yogi Bera
14 REPLIES 14
Rick Garland
Honored Contributor

Re: stopping cron

Can get the PID for cron via the ps -ef | grep cron.
Issue a kill command for the PID. (Avoid kill -9).
To restart, can issue the /usr/sbin/cron command
Phil Corchary
Advisor

Re: stopping cron

No can do. "cron" respawns (presumably via init).

I had been using /sbin/init.d/cron stop|start ... this just issues the self-same kill to the cron PID.

I need another way.
99% of the game is half mental. - Yogi Bera
Rick Garland
Honored Contributor

Re: stopping cron

Is it in the inittab?
Anthony Goonetilleke
Esteemed Contributor

Re: stopping cron

Thats a bit wiered Ive checked a few machines and cannot find cron in inittab, there are a few good reasons for doing this actually, but personally I would want to know why cron is dying before I respawn it.
The best way to go is probably take it out of inittab and then you can simply do

/sbin/init.d/cron stop
/sbin/init.d/cron start

Minimum effort maximum output!
Ramesh Donti
Frequent Advisor

Re: stopping cron

Hi,
Stop the cron issuing
/sbin/init.d/cron stop
and there is no chance of respawning of cron once again.

Once ur work is done, restart the cron by
/sbin/init.d/cron start.

I have done this atleast thousand times, so I assure u to go ahead.
Always Keep Smiling
Ralf Hildebrandt
Valued Contributor

Re: stopping cron

If cron is in the inittab, comment it out, kill it and the start it again by either putting it back into inittab and SIGHUP'ing init or /sbin/init.d/cron start
Postfix/BIND/Security/IDS/Scanner, you name it...
Jaikishan_1
Advisor

Re: stopping cron

Hi Dear,

#./sbin/init.d/stop cron
Do your Job
#./sbin/init.d/start cron

Go Ahead it`s really very safe and right way.
Rgds
Jaikishan
Don`t Give Up........
Victor BERRIDGE
Honored Contributor

Re: stopping cron

Now its not elegant but works, until you have solved you cron start/stop,
You can always move what you find in
/var/spool/cron/crontabs to somewhere else, and put all back after you backup has finished
No?
Just a suggestion...

Victor
Phil Corchary
Advisor

Re: stopping cron

There is actually a script in place from a previous SysAdmin that checks/restarts cron. I don't know why, or what the history behind it is, therefor I'm reluctant to comment it out of inittab.

I think the last suggestion of moving crontab is maybe the best.

philc
99% of the game is half mental. - Yogi Bera
Antoanetta Naghiu
Esteemed Contributor

Re: stopping cron

It is not a really way to go if you don't know way.
Anthony Goonetilleke is right. In a standard machine you do not have cron (and I see not reason to have it in inittab). But, to try to debug it, would you like to post the inittab line about cron?
Rick Garland
Honored Contributor

Re: stopping cron

Move the crontabs for ALL users. Unless you go through each user cron entry how are you going to know if something is be accessed during the backups?

Any chance on checking the script that is called from inittab?
Phil Corchary
Advisor

Re: stopping cron

Here is the line from /etc/inittab:
# grep cron /etc/inittab
cchk:234:respawn:/usr/bin/sh /home/bvb/croncheck.sh > /tmp/croncheck.log 2>&1

Here is the script:
# more croncheck.sh
#!/bin/sh
# croncheck.sh: by XXXXXXXXXXXXXXX, put in place on 3/29/00
# Special purpose script, designed to check/restart /usr/sbin/cron only.
# Designed to be run from /etc/init; inittab entry might look like:
# cchk:234:respawn:/usr/bin/sh /home/bvb/croncheck.sh > /tmp/croncheck.log 2>&1

while true
do
ps -ef | grep -v grep | grep /usr/sbin/cron >/dev/null
if [ $? -ne 0 ]
then
echo "$0: `date` /usr/sbin/cron not running, restarting now"
echo "$0: `date` /usr/sbin/cron not running, restarting now" | mail root
/usr/sbin/cron &
fi
sleep 120 # check every five minutes
done

I agree that I would need to move all user crontabs (there really should only be root and oraprod on these systems).

There's no mystery about the initab script or HOW it works, just why. I'm told by manager that there may have been an issue on 1 (or 4) systems with cron dying, but no one is sure.

philc
99% of the game is half mental. - Yogi Bera
Rick Garland
Honored Contributor

Re: stopping cron

I agree with a previous post. Why is cron dying on 1 (or 4) machines?
Do the syslogs indicate anything? cron should not be dying out. The entry in the inittab is not really necessary if you know why the cron is dying.

There are reasons for having the inittab entry but this seems like more of a workaround that the true solution. And it seems that it is preventing you from doing your original task.
Antoanetta Naghiu
Esteemed Contributor

Re: stopping cron

Which version of HP-UX are you running?
The script has been implemented in 99. Check for cron patches.
e.g. for HP-UX 11.0 I do have installed PHCO_17553 Y2K cummulative cron.
Go under forum/individual patches and check for cron patches. You may find even newer released. Read the description and if you do not have the patches installed, installed them. The script might be just the work around before the patch....