Operating System - HP-UX
1753707 Members
5071 Online
108799 Solutions
New Discussion юеВ

Re: script to check/start process

 
SOLVED
Go to solution
Ahmed_58
Regular Advisor

script to check/start process

Hi,
I need a script to:
1. check a process "ps -ef | grep ecoc"
2. if display "/opt/vantage/bin/ecocComputer-p 1 -t 0"
3. OK, then exit.
4. else start/execute "/opt/vantage/bin/restart_ecoagt

thanks,
Ahmed
7 REPLIES 7
Stephan._1
Trusted Contributor

Re: script to check/start process

Hi,
quick & dirty and not tested but should give you an idea


#!/usr/bin/sh
ps -ef | grep eoc

If [ $? = 0 ]; then
exit 0
else
/opt/vantage/bin/restart_ecoagt
fi
Share what you know, learn what you don't.
Hakki Aydin Ucar
Honored Contributor

Re: script to check/start process

better approach is to find exact pattern first:

instead of ps -ef | grep eoc use:
ps -ef | grep -w eoc
Suraj K Sankari
Honored Contributor

Re: script to check/start process

Hi,
It should like this

#!/usr/bin/sh
ps -ef | grep eoc
If [ $? = 0 ];
then

/opt/vantage/bin/ecocComputer-p 1 -t 0

else

/opt/vantage/bin/restart_ecoagt

fi

Suraj
Hakki Aydin Ucar
Honored Contributor

Re: script to check/start process

On second thought, that is better way:

ps -ef | grep -w ecoc | grep -v grep
Ahmed_58
Regular Advisor

Re: script to check/start process

Hi,
it looks the RC is always "0" as it is not excuting the else command to restart the process!

ps -ef | grep ecoc
#ps -ef | grep -w ecocComputer
if [ $? = 0 ]; then
echo ServerVantage is OK running with ecocComputer process...
else
/opt/vantage/bin/restart_ecoagt
fi
john korterman
Honored Contributor
Solution

Re: script to check/start process

Hi Ahmed,

ps -ef | grep whatever
will in most cases return at least the process line for the grep command, and therefore you get "0".

Instead of
ps -ef | grep ecoc
try this line:
$(UNIX95= ps -C ecoc > /dev/null)

the space after the equal sign is important!

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

Re: script to check/start process

thanks to all, special thanks to John,
script now working.
points also given.