Do actions based on if-else condition if a string Is found on stdout
by blueray from LinuxQuestions.org on (#54FRY)
@berndbausch has given a solution to stop the running command if a String Is found on stdout. Which is:
Code:ping google.com > /tmp/pingoogle &
PING=$!
while ! grep -q time=49.5 /tmp/pingoogle
do sleep 1
done
kill $PINGNow I want to run command based on condition.
For Example:
if icmp_seq=10 is found echo "10 pings"
if icmp_seq=20 is found echo "20 pings"
if icmp_seq=30 is found then kill $PING
Can anyone can help me do that?


Code:ping google.com > /tmp/pingoogle &
PING=$!
while ! grep -q time=49.5 /tmp/pingoogle
do sleep 1
done
kill $PINGNow I want to run command based on condition.
For Example:
if icmp_seq=10 is found echo "10 pings"
if icmp_seq=20 is found echo "20 pings"
if icmp_seq=30 is found then kill $PING
Can anyone can help me do that?