Sunday, October 28, 2012

Hosts Online (Working on 12.10)

So out of the whopping four scripts I have written, this was still the biggest pain in the arse to fix for 12.10, although that was expected because it was the biggest pain in the arse to write for 7.04. The good news is with 12.10 it is farrrr less complicated. It still works the same as it did 5 years ago, however. The script "hostsonline" is run in the background (ideally started at startup,) and it will place a file named ".hostsonline" inside of your home directory every 30 seconds. This file will contain a list of all the hosts connected to your LAN. (To reiterate why I did it this way instead of just outputting the script directly to conky, nmap (the program the script is built off of) takes a while to "resolve." IF I loaded nmap directly into conky, it would jam it up and slow down the other modules. So this way all conky has to do is read a file that is updated every 30 seconds, and it will instantly update in conky. This also helps conky not return an incomplete list if conky updates while nmap is running.

Anyway, without further ado, here she is.

//Start of 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. Essentially
# this script will create a file in your home directory
# called ".hostsonline," which will update every thirty
# seconds, and will contain a list of all IP Addresses
# currently assigned on your current network.
#
# Initial variables. Change "wlan0" to reflect your network interface. (Check in "ifconfig")
# You also need to install nmap, apcalc, and dog for this script to function correctly..

rawlist=$(nmap -sP 192.168.1.0/24 | grep 'Nmap scan report' | sed 's/[^0-9.]*//g')
while :
do
rm ~/.rawlist
rm ~/.hostsonline
echo $rawlist >> ~/.rawlist
tr ' ' '\n' < ~/.rawlist >> ~/.hostsonline
sleep 30
done


// End of Script

This should be called in conky like this:

${color #ffcb48}Hosts Online:
${color #FFFFFF}${execi 5 cat ~/.hostsonline}


And it will output like:

Hosts Online:
192.168.1.2
192.168.1.8
192.168.1.12

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 

System Info (Working on 12.10)

Well I got Ubuntu 12.10 on and loaded up conky and some of the scripts from this project. Conky worked fine. My scripts didn't work at all. Huge surprise there. So far I've been able to spend a whopping 20 minutes trying to fix them, so all I have so far is an updated sysinfo script. The main difference here is that instead of using 'cat' to display the relevant data out of /proc/acpi/battery, we can just use the program "acpi," with an output that looks like the following:

jason@kaito:~/bin$ acpi
Battery 0: Discharging, 25%, 00:24:46 remaining


As you can see, this output is a lot better for my purposes then the old method, which didn't display the battery life as a percentage, but as a number out of 4000 (in the case of my old laptop,) requiring me to declare variables in the script that did simple math to calculate the actual percentage. Not terribly difficult, but annoying. Another advantge to this output is the fact that all pertinent data is on one line, making this script quick work with some simple 'awk' parameters. Anyway, without further ado, here's the updated script. A lot cleaner, but outputs exactly the same.

//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: You'll need to install hddtemp (available in the repo's) and
# change the path to match your hard drive.

life=$(acpi | awk '{ print $4 }' | awk -F , '{ print $1 }')
temp=$(sudo hddtemp /dev/sda | awk -F: {' print $3 '} | awk {' print $1 '})
status=$(acpi | awk '{ print $3 }' | awk -F , '{ print $1 }')


echo CPU Temperature: $temp
echo Battery Life: $life
echo "Battery:" $status


//End Script

As always, you're going to call the script in conky the same way:

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


And it will output the following through Conky:

System Info:
CPU Temperature: 38*C
Battery Life: 47%
Battery: Charging 

Alright! Hopefully the other scripts are equally as easy to clean up. Hopefully I'll be posting them in not too much time at all.

(As a side note, I'll be changing the label of the old script to "development" and this one to "scripts," so each one will have to be accessed with it's respective side link. It just wouldn't make sense to have a non working script in the "scripts" section.)


Tuesday, October 23, 2012

Typo genocide!

Apparently my spelling drastically improved over the last 3 years...just annihilated a massive amount of grammatical and spelling errors. And on a side note, what was with my compulsion to sign every post with an encrypted pgp signature? What a weird kid... I was gonnah go edit all them out, but I think I'll keep them in just for laughs...

Here we go again...

And 3 years later, I found it again! But this time I totally forgot it existed...so reading through it all was quite weird...I don't recall typing 90% of this. However, since good ol' Windows 7 just started slugging out on me, I've decided to wipe it and give the latest Ubuntu Linux a try. Once that's on I definitely wannah get this up and running on my end because...well...I apparently put a decent amount of work into it and it looks rather nice.

So here's to hoping I'll make another post before 2015. It'd be nice to get working on some new scripts.

-Jason

Sunday, June 7, 2009

Wow...this is still on the internet?

I just found this again...I guess I'll set it up on my current box and see if it still works as described, and if so, I guess I'll pick up where I left off. My last post was about one year ago...so this should be interesting.

Friday, August 29, 2008

Back up and running

Well, I just officially lost the domain. No worries, I'll just use Bloggers hosting until I decide whether or not to get a new one. Anyway...not much has been done on this project. It seems I only work on this thing when I'm in between classes, and seeing that I took a semester off, there were no classes to be in between. However, everythings back to normal, and work will continue. I'm going to put a hold on module development until I have a basic install script working. Once thats done it should be easy to modify to accommodate new modules. Anyway, that's all for now...more to come.

-Jason