Thursday, February 7, 2008

Network Info Script (Obsolete as of Ubuntu 12.10)

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1


Alright heres the second script I wrote for my Conky setup. Its the first part of the network information section. Basically it retries your wireless ESSID, the connection strength (utilizing apcalc and ipconfig,) and your internal IP address. (For now it stops at the internal address, but I'm thinking about adding on a place for the external address.)

Here it is--be sure to change all necessary variables to match your specs.

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

# Variables. Don't change these.
network=$(iwconfig ath0 | grep ESSID | awk -F'"' '{ print $2 }')
one=$(iwconfig ath0 | grep Quality | awk -F= {' print $2 '} | awk -F/ {' print $1 '})
two=$(iwconfig ath0 | 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 ath0 | 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
echo "Link Quality:" $quality%
else
echo "Link Quality:" $quality"0%"
fi
# End of Link Quality loop.
echo "Address:" $netaddr

// End of Script


Theres nothing more to mention about this one except to replace "ath0" with whatever your device may be.

To call it in conky all you need is:

${color #ffcb48}Network Info
${color #FFFFFF}${execi 5 networkinfo}


And it outputs like:

Network Info
Connected To: Gotti
Link Quality: 47 %
Address: 192.168.2.104


I'm thinking about putting in options for a wired connection, I'll just leave them in as comments with the option to uncomment to activate them.

Next I'm going to work on my filespace info script before finishing up on parts 2 and possibly three of the network info.
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.6 (GNU/Linux)
Comment: http://firegpg.tuxfamily.org

iD8DBQFHq5ZDTiCACtcRvugRAiZNAJ0VEPEDLVSN8KbMevJcCWA9eQid1ACfYGLF
7205lZ82eB5yGEWJWxmYmeg=
=YLZP
-----END PGP SIGNATURE-----

No comments: