#!/bin/bash ### Edit RECEIVER_LIST to contain on line for each Kiwi in the "NAME IP:PORT" format declare RECEIVER_LIST=(\ "KIWI_2 10.14.70.72:8073" \ "KIWI_3 10.14.70.73:8073"\ "KIWI_4 10.14.70.74:8073"\ "KIWI_5 10.14.70.75:8073"\ "KIWI_6 10.14.70.76:8073"\ "KIWI_7 10.14.70.77:8073"\ "KIWI_8 10.14.70.78:8073"\ ) ### define the function function kiwi-stats () { local kiwi_list=(); local rx_line for rx_line in "${RECEIVER_LIST[@]}"; do local rx_fields=(${rx_line}); local rx_name=${rx_fields[0]}; local rx_ip_port=${rx_fields[1]}; if [[ ${rx_name} =~ AUDIO* ]] || [[ ${rx_name} =~ MERG* ]] || [[ ${rx_name} =~ RTL* ]]; then [[ ${verbosity} -ge 1 ]] && echo "skipping rx ${rx_name}"; else local rx_ip=${rx_ip_port/:*/}; if ! ping -c 1 -W 1 ${rx_ip} > /dev/null; then echo "WARNING: the Kiwi '${rx_name}' defined in ${wsprconf_file} doesn't repond to pings"; else kiwi_list+=(${rx_name},${rx_ip_port}); [[ ${verbosity} -ge 1 ]] && echo "Added ${rx_name} => ${rx_ip}"; fi; fi; done; [[ ${verbosity} -ge 1 ]] && echo "kiwi_list[@] => ${kiwi_list[@]}"; [[ ${verbosity} -ge 1 ]] && echo; local users; local users_max; local gps_good; local users_total=0; local wsprdaemon_total=0; local channels_total=0; for kiwi_info in "${kiwi_list[@]}"; do local kiwi_name=${kiwi_info%,*}; local kiwi_ip=${kiwi_info#*,}; local kiwi_status="$(curl -s http://${kiwi_ip}/status)"; users=$(sed -n '/users=\(.*\)/s//\1/p' <<< ${kiwi_status}); users_max=$(sed -n '/users_max=\(.*\)/s//\1/p' <<< ${kiwi_status}); channels_total=$((channels_total + users_max)); gps_good=$(sed -n '/gps_good=\(.*\)/s//\1/p' <<< ${kiwi_status}); [[ ${verbosity} -ge 1 ]] && printf "%15s: %d channels, %d users, %2d GPS satellites tracked\n" "${kiwi_name}" "${users_max}" "${users}" "${gps_good}"; curl -s http://${kiwi_ip}/users | sed -n 's/"i":\([0-9]*\)/\n\1/g ; s/},{//g ; p' | sed '/\[{/d; s/}]//; s/,/ /g' > /tmp/curl.log; while read user_line; do if grep --color=auto -q wsprdaemon <<< "${user_line}"; then [[ ${verbosity} -ge 1 ]] && echo "skipping WD user"; wsprdaemon_total=$((wsprdaemon_total + 1)); else if [[ -n "${user_line:1}" ]]; then eval declare $(echo "${user_line:1}" | sed '/"\([^"]*\)":/s//\1=/g'); local listener_channel="${user_line:0:1}"; local listener_name="$(echo "$n" | sed 's/%20/ /g')"; local listener_location="$(echo "$g" | sed 's/%20//g')"; local listener_freq="$f"; local listener_mode="$m"; local listener_ip="$a"; local listener_time="$t"; printf "%12s:%s %15s %8s %3s %s %20s %s\n" "${kiwi_name}" "${listener_channel}" "'${listener_name}'" "${listener_freq}" "${listener_mode}" "${listener_time}" "${listener_ip}" "${listener_location}"; users_total=$((users_total + 1)); fi; fi; done < /tmp/curl.log; done; printf "Found %d Kiwis configured for %d total rx channels, %d total listeners, %d wsprdaemon channels\n" "${#kiwi_list[@]}" $channels_total $users_total $wsprdaemon_total } ## Execute the function kiwi-stats