I have below code, that check abcd that is fine, when it not find abcd it check for 1 minutes that is also fine but i want one enhancement when it failed at the end it print "please check again" but if i add this line after fi statement it is constantly printing, i don't want that, please suggest.
tp=1
while [ $tp -le 2]
do
echo
command=`ls -l |grep abcd`
if [ "$command" == "123" ]
then
echo "ok"
break
else
let tp++
sleep 30
echo "nook"
fi
done
You could check the value of $tp (which will be 3 if you fail) before outputting your warning message. Alternatively, explicitly set a variable inside the 123 check to indicate that you succeeded, and check that.
To check condition again you can use infinite loop something like this
#!/bin/bash
x=0
while :
do
n=0
while [ $n -le 5 ];do
if [ $n -eq 3 ]; then
echo "Going to Break internal while loop but will check again" $x
break
fi
n=$((n+1))
done
x=$((x+1))
done