ping: show only results
Another awk
variation:
ping -qc1 google.com 2>&1 | awk -F'/' 'END{ print (/^rtt/? "OK "$5" ms":"FAIL") }'
-F'/'
- treat slash/
as field separator
Example output:
OK 47.090 ms
There’s not much you can do with ping
itself, but you can do all the processing in AWK, reducing the number of pipes, processes etc.:
ping -qc1 google.com 2>&1 | awk -F/ '/^rtt/ { printf "OK %.2f ms\n", $5; ok = 1 } END { if (!ok) print "FAIL" }'