1846842 Members
4858 Online
110256 Solutions
New Discussion

Re: Checking on cron

 
SOLVED
Go to solution
Marty Metras
Super Advisor

Checking on cron

Every once in a while the cron process fails.
Meaning it is not running.
I need a process that checks to see if the cron process is not running and starts it.
Since I can not have a job running in cron to do that, how do I make a process run as a daemon.
I don't know how to start a job to run as a process.
Can you point me to how to do it?
Simple script could be some thing like this:
# test_cron.sh
while [ true ]
do
if [ `ps -ef|grep cron|wc -l` -lt 1 ];then "start cron";fi
sleep 10800 # 3 hrs
done
# end
The only thing that always remain the same are the changes.
9 REPLIES 9
Pete Randall
Outstanding Contributor

Re: Checking on cron

Marty,

I would be more intersted in why cron is stopping. Have you checked /var/adm/syslog/syslog.log and /var/amd/cron/log to see if there's any indication of problems there? Have you applied the latest cron patches?


Pete

Pete
Mark Greene_1
Honored Contributor

Re: Checking on cron

Cron should be started by init; do ps -ef |grep cron to see what the parent pid is. It should be 1.

Also look in /var/adm/cron/log, /var/adm/syslog/syslog.log, and /var/adm/messages for any error messages about cron.

mark
the future will be a lot like now, only later
Steven E. Protter
Exalted Contributor

Re: Checking on cron

cron is usually as reliable as gravity.

Something is happening to stop the daemon.

Maybe:
http://www1.itrc.hp.com/service/patch/patchDetail.do?BC=patch.breadcrumb.main|patch.breadcrumb.search|&patchid=PHCO_26562&context=hpux:800:11:11

Don't know why this one came up but its worthwhile to have in.

http://www1.itrc.hp.com/service/patch/patchDetail.do?BC=patch.breadcrumb.main|patch.breadcrumb.search|&patchid=PHCO_30598&context=hpux:800:11:11

If I got the OS wrong, next time post it so I can give you the righ patches.

SEP
Steven E Protter
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com
Pete Randall
Outstanding Contributor
Solution

Re: Checking on cron

Here's the latest cron patches:

11.11 - PHCO_26562 http://www2.itrc.hp.com/service/patch/patchDetail.do?BC=patch.breadcrumb.main|patch.breadcrumb.pdb|patch.breadcrumb.search|&patchid=PHCO_26562&context=hpux:800:11:11
11.0 - PHCO_27141 http://www2.itrc.hp.com/service/patch/patchDetail.do?BC=patch.breadcrumb.main|patch.breadcrumb.pdb|patch.breadcrumb.search|&patchid=PHCO_27141&context=hpux:800:11:00
10.20- PHCO_27422 http://www2.itrc.hp.com/service/patch/patchDetail.do?BC=patch.breadcrumb.main|patch.breadcrumb.pdb|patch.breadcrumb.search|&patchid=PHCO_27422&context=hpux:800:10:20


Pete

Pete
Marty Metras
Super Advisor

Re: Checking on cron

I am 97% sure I know why cron is stopping.
When I am working on some other scripts that I have to kill I might be killing the wrong PID. I have always traced it back to some thing I was doing when I found it was not running. It only happen once or twice a year. And since I have almost every thing automated I just thought I could check on cron too.
All my process are running through cron so I wanted to check on cron too.
Marty
The only thing that always remain the same are the changes.
G. Vrijhoeven
Honored Contributor

Re: Checking on cron

Hi Marty,

I would look at your patch level before creating a work around for something that should work!

What is your O.S. Patch level:
check for patches at :

http://www5.itrc.hp.com/service/patch/search.do?BC=patch.breadcrumb.main|&pageContextName=hpux:::
for 11.11
http://www5.itrc.hp.com/service/patch/patchDetail.do?BC=patch.breadcrumb.main|patch.breadcrumb.search|&patchid=PHCO_26562&context=hpux:800:11:11

Regards,

Gideon
Marty Metras
Super Advisor

Re: Checking on cron

Gideon,

I agree, I will do the Patches. Maybe I am not doing it to myself.

The link you gave me is Europe. It will not let me connect saing that I am logged in.
Do you hav another Link in the US. or is this to PHCO_27141 that I can get to?
I have HP-UX 11.0.
Marty
The only thing that always remain the same are the changes.
Pete Randall
Outstanding Contributor

Re: Checking on cron

Marty,

Then maybe it's the way you're killing things - you're probably using "ps -ef |grep use_name" to identify the processes and end up picking up some stray processes along the way. Try this instead:

PROCESSES=`UNIX95= ps -U $USERNAME | grep -v PID |awk '{ print $1 }' | sort
-n`
for PROC in $PROCESSES
do
echo "\tKilling process $PROC"
kill $PROC
done


Pete

Pete
Bill Hassell
Honored Contributor

Re: Checking on cron

And to second what Pete said: grep and ps are a deadly combination in scripts that kill processes. I would remove the grep from all your scripts ASAP. The reason is that grep is not exclusive to a particular field or even a whole word. If you wanted to kill all the sh processes, you might be tempted to use:

PROCESSES=$(ps -ef|grep sh)

but you would then have a list containing unhashdaemon (big mistake), sshd (also a big mistake), and even ksh, csh, bash. What you need to do is to ask ps to search for you. ps can search by userID and also by exactmatch program name. ps -u some_user will give you all the processes for a single user, even if logged on multiple times. UNIX95 must be set to use the very useful option -C:

UNIX95= ps -f -C sh

And now you'll see ONLY sh processes.

As mentioned, cron never dies unless it was accidently killed and if so, you need to rehabilitate the killer...for it will kill again, perhaps randomly.


Bill Hassell, sysadmin