Thursday, February 7, 2008

System Info Script (Obsolete as of 12.10)

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


Heres the first script I whipped up for use with conky. Its nothing special, and it's really quite simple. Quite obviously this was made for use with a laptop, as it displays battery life and charging status. However, this can be easily changed to display any information you may require (uptime, disk load, etc.) In time I'm going to start working on scripts that I myself may not use, but some that others might find useful.

Anyway, heres the script:

// Begin 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. Change "BAT1" to reflect your battery. (Check in /proc/acpi/battery)
# You also need to install hddtemp, and change the path to the HDD to match yours.
remaining=$(cat /proc/acpi/battery/BAT1/state | grep remaining | awk '{ print $3 }')
life=$(calc $remaining/4000 | awk -F. '{ print $2 }' | head -c 2)
temp=$(sudo hddtemp /dev/sda | awk -F: {' print $3 '} | awk {' print $1 '})
wordcount=$(cat /proc/acpi/battery/BAT1/state | grep charging | awk '{ print $3 }' | wc | awk '{ print $3 - 1 }')
capital=$(cat /proc/acpi/battery/BAT1/state | grep charging | awk '{ print $3 }' | head -c 1 | tr '[a-z]' '[A-Z]')
rest=$(cat /proc/acpi/battery/BAT1/state | grep charging | awk '{ print $3 }' | tail -c $wordcount)


echo CPU Temperature: $temp
if [ $remaining = 4000 ]
then
echo Battery Life: 100%
else
echo Battery Life: $life%
fi
echo "Battery:" $capital$rest


// End Script

The value "4000" was obtained by looking in /proc/acpi/battery/BAT#/info and using the last full capacity value. Make sure this is correct or the percentage will be off.

And the "capital" and "rest" variables are there to capitalize the first letter of the battery status. I know it's hackish, but it was the quickest thing I could come up with, and it works fine.

Now heres the part where I talked about organization. No matter how sloppy the script gets, all you have to put in .conkyrc is the following:

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


And to remove the sysinfo section from conky, you just have to delete those two lines. This makes organizing the separate "modules" inside conky a breeze.

Lastly, when all is said and done, this script will output like the following:

System Info:
CPU Temperature: 37 C
Battery Life: 59%
Battery Status: Discharging


Thats all for now, more scripts later.
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.6 (GNU/Linux)

iD8DBQFHqy32TiCACtcRvugRAgtpAJ4xrDZehpeXeX7mhHE9QglB4Zj6RgCeOrib
ge3wvbc3ZOhWeZiVj7NjDW4=
=BFr5
-----END PGP SIGNATURE-----

No comments: