1825768 Members
2101 Online
109687 Solutions
New Discussion

again my script!

 
SOLVED
Go to solution
leyearn
Regular Advisor

again my script!

in order to check whether rpcd daemon is running on my system
(os hpux 10.10)

i write a script ,if it doesn't exist in my system ,start the rpcd daemon!
my script:

#!/usr/bin/sh

RPCD=$(ps -ef|grep -v grep|grep -c rpcd)
if [ $RPCD -eq 0 ]
then
/opt/dce/sbin/rpcd >>/script/rpcd/error.log2>&1
date >>/script/rpcd/date
fi

my cron is set (ervery five minute to check):

0,5,10,15,20,25,30,35,40,45,50,55 * * * * /script/rpcd/shell >>/script/rpcd/error.log 2>&1


i can execute the script manually,but cron can't
why?




26 REPLIES 26
leyearn
Regular Advisor

Re: again my script!

the way that i start rpcd is right or not
Mark Grant
Honored Contributor

Re: again my script!

Hi,

Firstly, you have two processes writing to the same file. This won't stop it working but looks a bit odd. Either re-direct the output to error.log in the script or in the crontab file but it probably isn't wise to do it in both.

Secondly, ensure there is a space before the 2>&1 within the script. There might actually be one already but it doesn't look like it in a web browser.

It's not the normal way to start rpcd but it is perfectly valid so I wouldn't worry too much about that.

Does your error.log provide any clue as to why cron is failing. It looks OK from here.
Never preceed any demonstration with anything more predictive than "watch this"
Con O'Kelly
Honored Contributor

Re: again my script!

Hi

Yes, you are starting rpcd correctly.
There should be a script called /sbin/init.d/Rpcd that starts it at boot time which you could use.

I'd guess your cron problem might be that it doesn't know the path to grep. If grep doesn't reside in /usr/bin, then you need the full path name.

Cheers
Con
leyearn
Regular Advisor

Re: again my script!

but the date command can work ok!
i change the "opt/dce/sbin/rpcd >>/script/rpcd/error.log2>&1 "
to

"opt/dce/sbin/rpcd >>/script/rpcd/error.log 2>&1 "
but the problem still exist!


Mark Grant
Honored Contributor

Re: again my script!

I have just noticed you are running 10.10 which explains why you don't have /sbin/init.d/Rpcd. I am not sure what shell /usr/bin/sh is on 10.10, is it still the posix shell? I sort of remember that early 10.X versions of HP-UX had a really buggy shell.

In cases like this, simplify!

try the following

ps -ef | grep -v grep | grep rpcd > /dev/null || {
/opt/dce/sbin/rpcd
}

See if it works
Never preceed any demonstration with anything more predictive than "watch this"
leyearn
Regular Advisor

Re: again my script!

i have viewed the /var/adm/cron/log file
the following is an entry :

CMD: /script/rpcd/shell >>/script/rpcd/error.log 2>&1
> root 8847 c Tue Sep 16 14:25:00 EAT 2003
< root 8847 c Tue Sep 16 14:25:00 EAT 2003


i prove that the cron well!

leyearn
Regular Advisor

Re: again my script!

i have viewed the /var/adm/cron/log file
the following is an entry :

CMD: /script/rpcd/shell >>/script/rpcd/error.log 2>&1
> root 8847 c Tue Sep 16 14:25:00 EAT 2003
< root 8847 c Tue Sep 16 14:25:00 EAT 2003


it prove that the cron well!

john korterman
Honored Contributor

Re: again my script!

Hi again,

there should be an error message in
/script/rpcd/error.log
saying what's wrong. Is that file empty?

Is the crontab for the same user as the command line user?

Check also /var/adm/cron/log for error messages.

regards,
John K.
it would be nice if you always got a second chance
Mark Grant
Honored Contributor

Re: again my script!

leyearn,

Please let us know the contents of /script/rpcd/error.log it will show any errors that cron is giving.
Never preceed any demonstration with anything more predictive than "watch this"
leyearn
Regular Advisor

Re: again my script!

i have checked the file /script/rpcd/error.log
but the file is empty!
Mark Grant
Honored Contributor

Re: again my script!

Have you tried this. Make your script /script/rpcd/shell

#!/usr/bin/sh
ps -ef | grep -v grep | grep rpcd > /dev/null || {
/opt/dce/sbin/rpcd
}

With a cron entry of 0,5,10,15,20,25,30,35,40,45,50,55 * * * * /script/rpcd/shell >> /script/rpcd/error.log 2>&1






Never preceed any demonstration with anything more predictive than "watch this"
john korterman
Honored Contributor

Re: again my script!

Hi again,

when you run the script manually, what happens?
Do you get any kind of messages?
The reason I ask is because that I think rpcd checks if it is already running, and if that is the case it will not start up another process. That could explain why apparently nothing happens in cron.

regards,
John K.
it would be nice if you always got a second chance
leyearn
Regular Advisor

Re: again my script!

to john korterman
i ever killed rpcd daemon manually!
but the script didn't start the rpcd!
i have test the
if [ $RPCD -eq 0 ]
was executed!

john korterman
Honored Contributor

Re: again my script!

Hi again,

could you try to modify your script to this:

#!/usr/bin/sh
echo before first command
RPCD=$(ps -ef|grep -v grep|grep -c rpcd)
echo $?
echo after first command
if [ $RPCD -eq 0 ]
then
echo true
/opt/dce/sbin/rpcd >>/script/rpcd/error.log2>&1
echo $?
date >>/script/rpcd/date
fi
echo ended


and then run it on the command line and from cron? Please post the output from both.

regards,
John K.
it would be nice if you always got a second chance
Mark Grant
Honored Contributor

Re: again my script!

leyearn,

Running out of ideas here but try running your script from cron but reading the users .profile as in

su - user -c "/script/rpcd/shell"
Never preceed any demonstration with anything more predictive than "watch this"
Zigor Buruaga
Esteemed Contributor

Re: again my script!

Hi,

Try to create other script that calls to "shell" script, and put it on cron.
What happens?

Kind regards,
Zigor
leyearn
Regular Advisor

Re: again my script!

my cron works well


my cron is set (ervery five minute to check):

0,5,10,15,20,25,30,35,40,45,50,55 * * * * /script/rpcd/shell >>/script/rpcd/error.log 2>&1


/var/adm/cron/log:

> CMD: /script/rpcd/shell >>/script/rpcd/error.log 2>&1
> root 15098 c Wed Sep 17 12:35:00 EAT 2003
< root 15098 c Wed Sep 17 12:35:00 EAT 2003

Mark Grant
Honored Contributor
Solution

Re: again my script!

Hello again leyearn :)

Cron is actually starting the job but the job it is running.

That's why I want you to try doing the "su user - c" thing I mention in my last post.

It will have the same environment as when you run your script from the command line.

Also, check roots mail for output from cron.
Never preceed any demonstration with anything more predictive than "watch this"
leyearn
Regular Advisor

Re: again my script!

to Mark Grant
thanks to you and all other !

but i run it when i am root !
i set up the cron as root too !
as you said
should i change the root's .profile file
and add an entry
su - root -c "/script/rpcd/shell" ?
Tom Geudens
Honored Contributor

Re: again my script!

Hi,
Before trying to use "su -" (which might be overkill) try running the script with "sh -x /script/rpcd/shell" in cron. That should show where it fails.

Regards,
Tom Geudens
A life ? Cool ! Where can I download one of those from ?
Mark Grant
Honored Contributor

Re: again my script!

Leyearn,

No, I am suggesting you do the su -root -c in your cron file. You say it works when you start it from the command line and I am trying to just make sure that it is not a problem with roots environment.

Let us know how it goes.
Never preceed any demonstration with anything more predictive than "watch this"
leyearn
Regular Advisor

Re: again my script!

i put the su - root -c into cron
and i killed the rpcd daemon manually
but when time comes
the rpcd daemon didn't start !
Mark Grant
Honored Contributor

Re: again my script!

Ok Leyearn, in that case, root should have received an e-mail explaining the problem. Have a look and see if you got anything.

Regards
Never preceed any demonstration with anything more predictive than "watch this"
leyearn
Regular Advisor

Re: again my script!

to Mark Grant


no mail for root in fact!