scripts/network.sh: use a list of hosts
- Use a list of hosts: google.com, github.com, example.com - Script will try each in turn, stopping at the first one that connects - Also fix she-bang and some quotes - Tested with Wifi and Offline.
This commit is contained in:
parent
b497fe68bd
commit
62537a8c6b
1 changed files with 14 additions and 9 deletions
|
@ -1,9 +1,10 @@
|
||||||
#/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
#author: Dane Williams
|
#author: Dane Williams
|
||||||
#script for gathering internet connectivity info
|
#script for gathering internet connectivity info
|
||||||
#script is called in dracula.tmux program
|
#script is called in dracula.tmux program
|
||||||
|
|
||||||
|
HOSTS="google.com github.com example.com"
|
||||||
|
|
||||||
get_ssid()
|
get_ssid()
|
||||||
{
|
{
|
||||||
|
@ -11,9 +12,9 @@ get_ssid()
|
||||||
case $(uname -s) in
|
case $(uname -s) in
|
||||||
Linux)
|
Linux)
|
||||||
if iw dev | grep ssid | cut -d ' ' -f 2 &> /dev/null; then
|
if iw dev | grep ssid | cut -d ' ' -f 2 &> /dev/null; then
|
||||||
echo $(iw dev | grep ssid | cut -d ' ' -f 2)
|
echo "$(iw dev | grep ssid | cut -d ' ' -f 2)"
|
||||||
else
|
else
|
||||||
echo ' Ethernet'
|
echo 'Ethernet'
|
||||||
fi
|
fi
|
||||||
;;
|
;;
|
||||||
|
|
||||||
|
@ -21,7 +22,7 @@ get_ssid()
|
||||||
if /System/Library/PrivateFrameworks/Apple80211.framework/Resources/airport -I | grep -E ' SSID' | cut -d ':' -f 2 &> /dev/null; then
|
if /System/Library/PrivateFrameworks/Apple80211.framework/Resources/airport -I | grep -E ' SSID' | cut -d ':' -f 2 &> /dev/null; then
|
||||||
echo "$(/System/Library/PrivateFrameworks/Apple80211.framework/Resources/airport -I | grep -E ' SSID' | cut -d ':' -f 2)"
|
echo "$(/System/Library/PrivateFrameworks/Apple80211.framework/Resources/airport -I | grep -E ' SSID' | cut -d ':' -f 2)"
|
||||||
else
|
else
|
||||||
echo ' Ethernet'
|
echo 'Ethernet'
|
||||||
fi
|
fi
|
||||||
;;
|
;;
|
||||||
|
|
||||||
|
@ -37,11 +38,15 @@ get_ssid()
|
||||||
|
|
||||||
main()
|
main()
|
||||||
{
|
{
|
||||||
if ping -q -c 1 -W 1 github.com &>/dev/null; then
|
network="Offline"
|
||||||
echo "$(get_ssid)"
|
for host in $HOSTS; do
|
||||||
else
|
if ping -q -c 1 -W 1 $host &>/dev/null; then
|
||||||
echo ' Offline'
|
network="$(get_ssid)"
|
||||||
|
break
|
||||||
fi
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
|
echo " $network"
|
||||||
}
|
}
|
||||||
|
|
||||||
#run main driver function
|
#run main driver function
|
||||||
|
|
Loading…
Reference in a new issue