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
Sunday, October 28, 2012
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
//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.)
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.)
Thursday, February 7, 2008
Disk Usage Script
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Before I put up the second part of the networking info script, heres a simple script that will display the freespace / usage of individual partitions on your hard drive. The main thing with this script is you have to manually edit in your partitions after the "grep" statement in the variable. Otherwise, you may get blank results.
// 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.
#
# If you don't have a seperate /home partiton, then just comment out
# all the variable lines having to do with a home partition, and all
# the echo lines having to do with /home.
#
# To add partitions to this script, simply follow the same format.
# To determine what to place after the grep command in the script,
# run "df -h" on a terminal, and use whatever is listed under "mounted on"
# for the desired partition.
# Home variables. (Comment out if you don't have a home partition.)
homesize=$(df -h | grep /home | awk {' print $2 '})
homeused=$(df -h | grep /home | awk {' print $3 '})
homefree=$(df -h | grep /home | awk {' print $4 '})
homeuseperc=$(df -h | grep /home | awk {' print $5 '} | awk -F% {' print $1 '})
homeperc=$(calc 100-$homeuseperc | awk {' print $1 '})
# Root variables.
rootsize=$(df -h | grep -w / | awk {' print $2 '})
rootused=$(df -h | grep -w / | awk {' print $3 '})
rootfree=$(df -h | grep -w / | awk {' print $4 '})
rootuseperc=$(df -h | grep -w / | awk {' print $5 '} | awk -F% {' print $1 '})
rootperc=$(calc 100-$rootuseperc | awk {' print $1 '})
# Root output.
echo "/ (root)"
echo " Size:" $rootsize
echo " Used:" $rootused
echo " Free:" "$rootfree ($rootperc%)"
# Home output. (Comment out if you don't have a home partition.)
echo /home
echo " Size:" $homesize
echo " Used:" $homeused
echo " Free:" "$homefree ($homeperc%)"
// End of Script
Again, be sure to edit in your partitions. As stated in the script, use "df -h" to help determine which partitions to use.
The script is called in .conkyrc like so:
${color #ffcb48}Disk Usage Info:
${color #FFFFFF}${execi 5 diskfreeinfo}
And it will output like this:
Disk Usage Info:
/ (root)
Size: 14G
Used: 3.0G
Free: 11G (77%)
/home
Size: 44G
Used: 1.8G
Free: 40G (95%)
Next is the second part in the networking info; Hosts Online.
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.6 (GNU/Linux)
iD8DBQFHq/HLTiCACtcRvugRApaRAJ0X07i2gY2r+mZ4bHA/Wuv0B1WLhQCfd5Zj
k2AwXN5+4T+/gwS7yBIZjZ4=
=qs0p
-----END PGP SIGNATURE-----
Hash: SHA1
Before I put up the second part of the networking info script, heres a simple script that will display the freespace / usage of individual partitions on your hard drive. The main thing with this script is you have to manually edit in your partitions after the "grep" statement in the variable. Otherwise, you may get blank results.
// 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.
#
# If you don't have a seperate /home partiton, then just comment out
# all the variable lines having to do with a home partition, and all
# the echo lines having to do with /home.
#
# To add partitions to this script, simply follow the same format.
# To determine what to place after the grep command in the script,
# run "df -h" on a terminal, and use whatever is listed under "mounted on"
# for the desired partition.
# Home variables. (Comment out if you don't have a home partition.)
homesize=$(df -h | grep /home | awk {' print $2 '})
homeused=$(df -h | grep /home | awk {' print $3 '})
homefree=$(df -h | grep /home | awk {' print $4 '})
homeuseperc=$(df -h | grep /home | awk {' print $5 '} | awk -F% {' print $1 '})
homeperc=$(calc 100-$homeuseperc | awk {' print $1 '})
# Root variables.
rootsize=$(df -h | grep -w / | awk {' print $2 '})
rootused=$(df -h | grep -w / | awk {' print $3 '})
rootfree=$(df -h | grep -w / | awk {' print $4 '})
rootuseperc=$(df -h | grep -w / | awk {' print $5 '} | awk -F% {' print $1 '})
rootperc=$(calc 100-$rootuseperc | awk {' print $1 '})
# Root output.
echo "/ (root)"
echo " Size:" $rootsize
echo " Used:" $rootused
echo " Free:" "$rootfree ($rootperc%)"
# Home output. (Comment out if you don't have a home partition.)
echo /home
echo " Size:" $homesize
echo " Used:" $homeused
echo " Free:" "$homefree ($homeperc%)"
// End of Script
Again, be sure to edit in your partitions. As stated in the script, use "df -h" to help determine which partitions to use.
The script is called in .conkyrc like so:
${color #ffcb48}Disk Usage Info:
${color #FFFFFF}${execi 5 diskfreeinfo}
And it will output like this:
Disk Usage Info:
/ (root)
Size: 14G
Used: 3.0G
Free: 11G (77%)
/home
Size: 44G
Used: 1.8G
Free: 40G (95%)
Next is the second part in the networking info; Hosts Online.
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.6 (GNU/Linux)
iD8DBQFHq/HLTiCACtcRvugRApaRAJ0X07i2gY2r+mZ4bHA/Wuv0B1WLhQCfd5Zj
k2AwXN5+4T+/gwS7yBIZjZ4=
=qs0p
-----END PGP SIGNATURE-----
Subscribe to:
Posts (Atom)