Link to home
Start Free TrialLog in
Avatar of csanter
csanterFlag for United States of America

asked on

How to use ps to monitor portmap instances and restart

I have some processes that i would like to monitor. Say for instance, i want to find out if portmap is running and the number of instances. If it is less than (say 2) I want to restart the process.

I did a:  ps- ef | grep portmap | grep -v grep |  grep -c portmap  - That gives me the count.
If i plug th same command in a script it does not seem to work. What am  I doing wrong?

This gives me error:

if [ [ps -ef | grep portmap | grep -v grep | grep -c portmap] < "2" ]  ; then
echo " Yes"
else
echo "No"
fi
~
[btoadmin@testlab154 ~]$ ./test.portmap
./test.portmap[8]: [: missing ]
./test.portmap[8]: cannot open 2: No such file or directory

I don't see the problem ...

This gives me error:
#!/bin/ksh

if [ `ps -ef | grep portmap | grep -v grep | grep -c portmap` < 2 ]  ; then
echo " Yes"

else
echo "No"
fi

I know i am doing something wrong, but i am not sure what...
Avatar of tfewster
tfewster
Flag of United Kingdom of Great Britain and Northern Ireland image

Your first example has an extra "[" (self explanatory)

Use "-lt" instead of "<" in your script
Avatar of csanter

ASKER

tfewster,

I started with -lt - it did not make a difference in the logic. At one point, I had no error, but the logic did not work.
One would expect a return value of "Yes" in this case, since portmap has one process - less than 2  I put above.
Instead, the value returned by the program is always  "No"
Thjank you

Avatar of csanter

ASKER

mplungjan,

Could you please explain your comment?
Avatar of Michel Plungjan
1. title was something like "How do I do this" which is non-informative, I changed it to reflect the actual question
2. You had cross posted in the JavaScript TA - I do not see any need for JavaScript here

mplungjan, ee page editor
ASKER CERTIFIED SOLUTION
Avatar of tfewster
tfewster
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial