Stop the running Command if a String Is found on stdout
by blueray from LinuxQuestions.org on (#54ET3)
How Can I close ping if a string is found in the output:
Code:$ ping google.com
PING google.com (74.125.130.138) 56(84) bytes of data.
64 bytes from sb-in-f138.1e100.net (74.125.130.138): icmp_seq=1 ttl=44 time=50.3 ms
64 bytes from sb-in-f138.1e100.net (74.125.130.138): icmp_seq=2 ttl=44 time=49.5 ms
64 bytes from sb-in-f138.1e100.net (74.125.130.138): icmp_seq=3 ttl=44 time=49.5 ms
64 bytes from sb-in-f138.1e100.net (74.125.130.138): icmp_seq=4 ttl=44 time=49.5 msNow I want something like:
Code:if ping google.com | grep -q 'time=49.5'; then
//terminate ping
fiSo that, if time=49.5 is there it will terminate ping command.


Code:$ ping google.com
PING google.com (74.125.130.138) 56(84) bytes of data.
64 bytes from sb-in-f138.1e100.net (74.125.130.138): icmp_seq=1 ttl=44 time=50.3 ms
64 bytes from sb-in-f138.1e100.net (74.125.130.138): icmp_seq=2 ttl=44 time=49.5 ms
64 bytes from sb-in-f138.1e100.net (74.125.130.138): icmp_seq=3 ttl=44 time=49.5 ms
64 bytes from sb-in-f138.1e100.net (74.125.130.138): icmp_seq=4 ttl=44 time=49.5 msNow I want something like:
Code:if ping google.com | grep -q 'time=49.5'; then
//terminate ping
fiSo that, if time=49.5 is there it will terminate ping command.