Computing.Net > Forums > Unix > Bourne shell error if/then/else

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Click here to start participating now! Also, check out the New User Guide.

Bourne shell error if/then/else

Reply to Message Icon

Name: elpico
Date: May 6, 2003 at 07:55:19 Pacific
OS: Solaris 8
CPU/Ram: 256
Comment:

Hi all,

I'm trying to get a if/then/else check with a integer comparison on wc -l, but not having much luck.

I want to check if there are a certain number of processes running, and if so, print sucess message/run something else.

So far all I get are errors when I do

#!/bin/sh
ps -ef | grep tomcat | if [wc -l -ne 2]; then echo "Not running"
else echo "Running"
fi

Any suggestions/ideas on where I'm going wrong?

Thanks in advance,
elpico.



Sponsored Link
Ads by Google

Response Number 1
Name: David Perry
Date: May 6, 2003 at 09:02:34 Pacific
Reply:

if [ `ps -ef | grep -c tomcat` -ne 2 ] ; then
echo "Not running"
else
echo "Running"
fi


0

Response Number 2
Name: elpico
Date: May 7, 2003 at 01:26:16 Pacific
Reply:

Thanks for that! - I think I was focusing too much on using the wc -l command.

Cheers,
elpico.


0

Response Number 3
Name: David Perry
Date: May 7, 2003 at 05:08:15 Pacific
Reply:

if [ `ps -ef | grep tomcat | wc -l` -ne 2 ] ; then
echo "Not running"
else
echo "Running"
fi


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More


IO Error on X server 2>&1 &



Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Unix Forum Home


Sponsored links

Ads by Google


Results for: Bourne shell error if/then/else

Unix, Script, If then else www.computing.net/answers/unix/unix-script-if-then-else/6446.html

IF-Then-Else syntax Help!!!! www.computing.net/answers/unix/ifthenelse-syntax-help/6684.html

I need help writing a bourne shell scrip www.computing.net/answers/unix/i-need-help-writing-a-bourne-shell-scrip/2184.html