Skip to content

Instantly share code, notes, and snippets.

@dan82840
Created November 3, 2016 03:57
Show Gist options
  • Save dan82840/c9f02d061e3cf1048ce312d8781083c5 to your computer and use it in GitHub Desktop.
Save dan82840/c9f02d061e3cf1048ce312d8781083c5 to your computer and use it in GitHub Desktop.
#!/bin/sh
#
# ./test-config-foreach.sh
# SSID wificity_f16e82_2G UP !!!
# SSID wificity_f16e82_guest DISABLED !!!
# SSID wificity_f16e82_5G UP !!!
# SSID wificity_f16e82_2G_1 UP !!!
# SSID wificity_f16e82_5G_1 UP !!!
# SSID wificity_f16e82_2G_2 UP !!!
# SSID wificity_f16e82_5G_2 UP !!!
# SSID wificity_f16e82_2G_3 UP !!!
# SSID wificity_f16e82_5G_3 UP !!!
# SSID wificity_f16e82_2G_4 UP !!!
# SSID wificity_f16e82_5G_4 UP !!!
# SSID wificity_f16e82_2G_5 UP !!!
# SSID wificity_f16e82_5G_5 UP !!!
# SSID wificity_f16e82_2G_6 UP !!!
# SSID wificity_f16e82_5G_6 UP !!!
# SSID wificity_f16e82_2G_7 UP !!!
# SSID wificity_f16e82_5G_7 UP !!!
# SSID wificity_f16e82_2G_8 UP !!!
# SSID wificity_f16e82_5G_8 UP !!!
# SSID wificity_f16e82_2G_9 UP !!!
# SSID wificity_f16e82_5G_9 UP !!!
# SSID wificity_f16e82_2G_10 UP !!!
# SSID wificity_f16e82_5G_10 UP !!!
# SSID wificity_f16e82_2G_11 UP !!!
# SSID wificity_f16e82_5G_11 UP !!!
# SSID wificity_f16e82_2G_12 UP !!!
# SSID wificity_f16e82_5G_12 UP !!!
# SSID wificity_f16e82_2G_13 UP !!!
# SSID wificity_f16e82_5G_13 UP !!!
# SSID wificity_f16e82_2G_14 UP !!!
# SSID wificity_f16e82_5G_14 UP !!!
# SSID wificity_f16e82_5G_15 UP !!!
# ./test-config-foreach.sh: eval: line 1: syntax error: bad substitution <-- Error here
#
. /lib/functions.sh
is_ssid_up() {
local ssid=$1
local retval=$2
local count=0
local hit=0
local inf _ssid
local line_num=$(cat /proc/net/wireless | wc -l)
[ "$line_num" == "2" ] && {
eval "export -- \"$retval=\"0\"\""
return
}
IFS=$'\n'
for line in $(cat /proc/net/wireless); do
count=$((count + 1))
[ "$count" == "1" -o "$count" == "2" ] && continue #skip 1st and 2nd line
inf=$(echo $line | awk -F":" '{print $1}' | sed 's/ //g')
[ "$inf" == "wifi0" -o "$inf" == "wifi1" ] && continue
_ssid=$(iwconfig $inf | awk -F '"' '/ESSID/ {print $2}')
if [ "$ssid" == "$_ssid" ]; then
hit=1
break
fi
done
eval "export -- \"$retval=\"\"$hit\"\"\""
}
# $1: section name
check_ssid_up() {
local section=$1
config_get ssid $section ssid
config_get disabled $section disabled
[ "$disabled" == "1" ] && {
echo "SSID $ssid DISABLED !!!"
return
}
is_ssid_up "$ssid" "rc"
if [ "$rc" == "0" ]; then
echo "Checking SSID $ssid !!!"
sleep 5
check_ssid_up $section
else
echo "SSID $ssid UP !!!"
fi
}
# $1: section name
check_ssid_cb() {
local section=$1
check_ssid_up $section
}
check_all_ssid() {
config_load wireless
config_foreach check_ssid_cb wifi-iface
}
main() {
check_all_ssid
check_all_ssid
}
main
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment