Greping return code error

Hi folks,

I am running below code which is giving me output "httpd (no pid file) not running", how can i grep this code in shell script.

I have tried below code but it is not giving me error in echoing.


./webserver stop

if [ $? -eq 0 ]

echo " Everything is OK"

else

echo "Error code $0 and output"

fi

error message below part.

./webserver stop
httpd (no pid file) not running
out=`./webserver stop 2>&1`
xstate=$?
if [ $xstate -eq 0 ]
echo " Everything is OK"
else
echo "Error code $xstate $out"
fi

It is always showing " WebServer is running OK". Not showing the error and neither code.


# x=`./webserver stop 2>&1`
# echo $?
0

webserver service is not working but it is still showing webserver is running ok.

What is in your webserver script?


./webserver stop [ it is stopping weberver ]
./webserver start [ it is starting weberver ]

It is starting webserver and also stop webserver, both are valid arguments so that's why it i not showing anything. Actually my motive of writing script is that if httpd process is present in memory or not, if not then start the apache process but main problem is that i am not able to grep httpd process because its very difficult to get apache process looks like that.