1838652 Members
3681 Online
110128 Solutions
New Discussion

check number of process

 
Muguerza
Occasional Contributor

check number of process

Do you know what is the operator or sintax for display a echo for check process -lt 2 and -gt 164 for example i have the next sintax: (My question is in ??)

PROCS=`ps -fu $USERID | grep FND |grep appltest|wc -l`
if [ $PROCS -gt 164 ];
then
echo "\n\t Process is running"
else
if [ $PROCS -lt 2 ];
then
echo
echo "\n\t Process is not running"
else
?? if [ $PROCS -lt 2 and -gt 164 ];
then
echo
echo "\n\t Process is waiting"
2 REPLIES 2
Patrick Wallek
Honored Contributor

Re: check number of process

Stop and think about your last if statement for a minute. Do you see any problem with your logic?

How is it possible for PROCS to be less than 2 adn greater than 164 at the same time? Answer -- It's not.

I **think** you may really mean if PROCS is greater than 2 and less than 164? Regardless your last statement is redundant. Get rid of it completely, like:

PROCS=`ps -fu $USERID | grep FND |grep appltest|wc -l`
if [ $PROCS -gt 164 ];
then
echo "\n\t Process is running"
elif [ $PROCS -lt 2 ];
then
echo
echo "\n\t Process is not running"
else
echo
echo "\n\t Process is waiting"
fi

Dennis Handly
Acclaimed Contributor

Re: check number of process

I'm not sure I get what the relation from number of processes and "running", "not running" and "waiting"? Unless you need 164 processes for the application to be "running"?

If you really really want to do that and you can use:
if [ $PROCS -lt 2 -a -gt 164 ]; then

As Patrick says, this will always be false.
You probably want:
if [ $PROCS -ge 2 -a -le 164 ]; then

And this will always be true because of your previous ifs.