Grep Stop status from the output of script and send an eamil alert.

Hello Team,

I have script which gives below output.

Server clustServer11 is in a STARTED state

Server clustServer12 is in a STOPPED state

Server clustServer21 is in a STOPPED state

I would like to prepare script which will grep stop word from the above output and send an email alert.

cat output | grep -i "stop" | mail -s "any subject" yourmail@foobar.com

I am getting this output.

./wsadmin.sh -lang jython -f serverstat.py | grep -i stopped | awk '{ print $2 }'
clustServer12
clustServer21

I have requiremnt to send mail with the server name which is stopped state.

---------- Post updated at 07:41 AM ---------- Previous update was at 05:52 AM ----------

bash-3.00$ ./wsadmin.sh -lang jython -f /opt/app/ccr/home/ccr/scripts/ccrserverstatus.py | grep -i start | awk '{ print $2 }' | while read server;
> do
> if [ $server = "clustServer1*" ]
> then
> echo "$server is running fine on ccrtoolsvcp1"
> else
> echo "$server is running fine on ccrtoolsvcp3"
> fi
> done
clustServer11 is running fine on ccrtoolsvcp3
clustServer12 is running fine on ccrtoolsvcp3
clustServer13 is running fine on ccrtoolsvcp3
clustServer21 is running fine on ccrtoolsvcp3
clustServer22 is running fine on ccrtoolsvcp3

My requirement is if server is clustserver11,12 and 13 then it should execute following echo command.

echo "$server is running fine on ccrtoolsvcp1"

and if server is clustserver21 and 22 then it should execute following echo command.

echo "$server is running fine on ccrtoolsvcp3"

But this is not happening now. It is going in else statement only and not comparing comment in if command.

Can anyone pls help me to correct script?

try

instead of

Hello Rohan,

Thanks for the response. But it didnt worked. It is not comparing string in if statement and directly going to else statement.

bash-3.00$ server=clustServer11
bash-3.00$ if [ "$server" = "clustServer1.*" ]
> then
> echo "$server is running fine on ccrtoolsvcp1"
> else
> echo "$server is not running"
> fi
clustServer11 is not running
bash-3.00$

execute

to debug the script