Marty Oehme
3bf5becbe2
Added script to sh base package to allow checking for internet connectivity. Checks both through system virtual filesystem and, as a fallback, through pinging google dns. Added a simple readme to sh module.
24 lines
451 B
Bash
Executable file
24 lines
451 B
Bash
Executable file
#!/usr/bin/env sh
|
|
#
|
|
# Check for internet connectivity.
|
|
# Returns 0 if connectivity exists, 1 if it does not.
|
|
|
|
hasconnec=0
|
|
for intf in /sys/class/net/*; do
|
|
case $intf in
|
|
"/sys/class/net/lo") break ;;
|
|
*)
|
|
[ "$(cat "$intf/carrier")" = 1 ] && hasconnec=1
|
|
;;
|
|
esac
|
|
done
|
|
|
|
if [ $hasconnec -ne 1 ]; then
|
|
ping -q -w 1 -c 1 8.8.8.8 >/dev/null 2>&1 && hasconnec=1
|
|
fi
|
|
|
|
if [ $hasconnec -eq 1 ]; then
|
|
exit 0
|
|
else
|
|
exit 1
|
|
fi
|