Saturday, October 27, 2012

Network Info (Working on 12.10)

Well this one was equally as simple to update...all I had to do was add an "elif" to the loop to fix an error where "100%" wouldn't display under link quality. Other then that just changing my wireless adapter to it's appropriate name got this script up and running rather quickly. Anyway...here it is.

//Begin Script

#!/bin/sh
#
# Script by Jason Gotti (email removed for spambots)
# Written and tested on Ubuntu 12.10.
#
# Developed for use with conky, but also can be used
# for other information related purposes.

# Variables. Change 'wlan0' to reflect your network adapter.
network=$(iwconfig wlan0 | grep ESSID | awk -F'"' '{ print $2 }')
one=$(iwconfig wlan0 | grep Quality | awk -F= {' print $2 '} | awk -F/ {' print $1 '})
two=$(iwconfig wlan0 | grep Quality | awk -F= {' print $2 '} | awk -F/ {' print $2 '} | awk {' print $1 '})
quality=$(calc $one/$two | awk -F. '{ print $2 }' | head -c 2)
qualitychars=$(calc $one/$two | awk -F. '{ print $2 }' | head -c 2 | wc | awk {' print $3-$1 '})
netaddr=$(ifconfig wlan0 | grep "inet addr" | awk -F: {' print $2 '} | awk {' print $1 '})

# Output
echo "Connected to:" $network
# This loop was added to fix a bug that displayed
# percentages ending in "0" (40, 50, 60) as one digit.
# Ex. 50% was displayed as 5%. This loop checks the word count
# of the quality variable and acts accordingly.
if [ $qualitychars = 2 ]
then

${color #ffcb48}System Info:
${color #FFFFFF}${execi 5 sysinfo}
echo "Link Quality:" $quality%
elif [ $one = $two ]
then
echo "Link Quality: 100%"
else
echo "Link Quality:" $quality"0%"
fi
# End of Link Quality loop.
echo "Address:" $netaddr


//End Script

I may still find errors in how the quality is displayed, but I won't be able to weed them out until I have the script running on my desktop for awhile so I can monitor it. Until then though, this should work fine on Ubuntu 12.10 and similar distros.

To call it in conky, as always, use the following code in .conkyrc.

${color #ffcb48}System Info:
${color #FFFFFF}${execi 5 sysinfo} 


The script will display like the following on your desktop through conky:

Network Info:
Connected to: Gotti
Link Quality: 97% 
Address: 192.168.2.1 

No comments: