Matching strings in unix shell programming

 
#!bin/sh
`clear`
for i in $(seq -w 15 37);
do
#echo $i
wget --dns-timeout=0.0005 http://napdweb${i}.eao.abn-iad.ea.com:8000/webcore/test/test.jsp -o 1
A=`cat 1`
C=$(expr "$A" : '.............................................................................................................................\(......................\)')
D=": Connection timed out"
if [ "$C" = "$D" ] ;
then
echo "napdweb${i} may be hung,Please restart the server"
else
echo "napdweb${i} is up and fine "
fi
done
 

HI , Please see the above program.I got the output but now i have to compare the strings "C" and "D" using matching concept.Can anyone tell me how can i compare those two strings using strings matching concept.

you already did : if [ "$C" = "$D" ]
where ist the problem ?

Ya i have done it but now i have to do the matching by using regular expressions.Can anyone tell me how it can be done.

If you're only looking for the string "Connection timed out" then try searching your wget log file directly using grep and test the exit status of that instead.

if grep -q "Connection timed out" 1; then 
echo "napdweb${i} may be hung,Please restart the server"
else
echo "napdweb${i} is up and fine "
fi

you can ommit the A, C, and D variables and change your test as suggested.

I already done it by using grep command, but according to our requirement , we have to do it bu using only regular expressions.Can anyone tell me hoe it can be done by using regular expressions in unix shell programming

expr $c : $d

Read the shell manual to see what is the differences between = and == :cool:

I have done it by using expreesions as below

expr $C : $D

But i am getting an error as command not found.

Can anyone tell me how to match strings in the above program using shell programming