I have this script to check for internet connectivity. I use ping for it. Whenever I use ping google.com -c 4 | grep time
it produces a non-empty response. Something like
64 bytes from hkg03s11-in-f4.1e100.net (173.194.127.68): icmp_req=2 ttl=52 time=90.6 ms
. But, when connectivity is down, the time
part does not show up, therefore, when I execute the same command, it shows up as empty. How do I use if
for it? I'm confused whether to use " "
or ""
.
Which one do I use?
if [ 'ping google.com -c 4 | grep time' != " " ]; then
or
if [ 'ping google.com -c 4 | grep time' != "" ]; then
Notice the space between the ""
$?
after running your ping. It'll be different values if it worked or not. – Sobrique Mar 16 '15 at 15:41