Hello,
I need a simple shell script that returns a value if the system is internet connected and a different value if the system is not connected.
Can anyone please help?
Thanks
Daniele
Hello,
I need a simple shell script that returns a value if the system is internet connected and a different value if the system is not connected.
Can anyone please help?
Thanks
Daniele
ping -c1 unix.com &>/dev/null && echo "online" || echo "offline"
online
Thanks
I wouldn't do just one ping ( -c1
). It is quite normal for the first ping to fail if there's not ARP table entry, and it would not be an indication that the node has lost network connectivity.
-c 3
or perhaps even -c 5
I would consider a more reliable metric.