1833883 Members
1779 Online
110063 Solutions
New Discussion

Re: about my script !

 
leyearn
Regular Advisor

about my script !

my net has been infected by the virus!
so the process of rpcd(on my hp workstation) is often be killed by the virus on the windows systems!
because of my 10.10 os ,there is no patch for it
so i write a script:

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

it can be run manually
but when i put it into cron
i will not be execute!
why?
10 REPLIES 10
Stefan Farrelly
Honored Contributor

Re: about my script !

Firstly you should change your grep -c line to grep -v grep or else or you will ocasionally pick up your own grep command instead of checking if rpcd is running;

RPCD=$(ps -ef|grep -v grep|grep -c rpcd)

The way to restart rpcd is;

/sbin/init.d/Rpcd start

Give that a try.
Im from Palmerston North, New Zealand, but somehow ended up in London...
Jean-Luc Oudart
Honored Contributor

Re: about my script !

You can reduce the nb of process being run

RPCD=$(ps -ef|grep -c [r]pcd)

Rgds,
JL

fiat lux
Kevin O'Donovan
Regular Advisor

Re: about my script !

I'm a small bit rusty on my scripting, but what shell do you run it in when you run it manually? Cron scripts are run in an sh shell, and I'm not sure about the if [ ] syntax works in sh...

You might want to try test instead, like:
if (test $RPCD = 0)

hope that helps,
Kevin.
Kevin O'Donovan
Regular Advisor

Re: about my script !

Actually you can probably scratch that, think test and [ ] are the same and both work in Bourne shell...

Have you checked the output from the cron, to see what exactly the error is?
leyearn
Regular Advisor

Re: about my script !

to Stefan Farrelly


i didn't find /sbin/init.d/Rpcd on my system

my os is hpux 10.10

i found /sbin/init.d/dce
can i use /sbin/init.d/dce start instead?

thanks!


Steven E. Protter
Exalted Contributor

Re: about my script !

Something to understand about cron.

The environment is minimal.

No TERM, limited PATH.

To avoid this, I make sure any scripts called by cron either have a complete PATH or each command has the full path of the binries you are calling.

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
leyearn
Regular Advisor

Re: about my script !

i have test the script
the problem may be the way that i start the rpcd daemon!

but i have use the absolute path : /opt/dce/sbin/rpcd

but in this situation
i can execute the script manually!

but cron can't!
john korterman
Honored Contributor

Re: about my script !

Hi,

The first line of your script should specify which shell to use, e.g.:
#!/usr/bin/sh

When you execute your script on the command line it is executed in your current shell - and that is probably not the same as the cron default shell. Therefore, specify the shell.
Anyway, what error do you get from cron?

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

Re: about my script !

Hi,

Try to redirect the output from your cron job to a log file and see if you get any error messages.

0,15,30,45 * * * * <script> >>/tmp/abc.log 2>1

Another solution for this may be to start rpcd from inittab with the respawn option.
john korterman
Honored Contributor

Re: about my script !

Hi again

I would suggest that you change
2>1
in Leif Halvarsson's suggestion to
2>&1

but if the output from a cron script is not redirected to a file, it is mailed to the crontab user; check also the mail messages.

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