puflogh300X74.gif

Polarwave's OpenBSD
Tips and Tricks for Newbies

| Conky System Statistics |

| Home | Tips and Tricks | Links | News Feeds | Fun | Contact | Blog (Opens in New Page) |


System Information on Your Desktop

Note:
Make sure you read the whole write up. There are quite a few addendums
to it since I learned more as I went along in using Conky.

Sometimes I just get lazy and don't want to open an xterm or rxvt window from X and
type in what I need to get system information, so I decided to give Conky a try. I used
pkg_add to install it. I'd looked at the Makefile and there was nothing special there,
so no point building a port when a package would do the job. Conky installs its binary
by default in /usr/local/bin, the documentation in /usr/local/share/doc, and sample
configuration files in /usr/local/share/examples/conky. I wish the docs would have
had more examples, but it's free open source, reliable and not too hard to figure out
once you do a little "Googling" around. Combining what I got from the documentation,
what I know about scripting, and examples I found searching the Internet, I eventually
came up with a working configuration that had all the data I needed on the desktop
and, also important, fit on my screen with my current resolution settings in X.
conky.conf is installed in /etc/conky/, but you can copy the sample configuration file
/usr/local/share/examples/conky/conkyrc.sample to your /home/usr/ directory as
.conkyrc, edit it according to your personal tastes and needs, and those settings will
take precedence over what's in the main conky configuration file.

First, here's what the final product looks like on my desktop:

Conky

conky_213x723_anon.png




System info. Day, date, timezone, and
time, uptime, kernel, and cpu.

Current cpu activity, load, processes,
and currently running.


Top 4 highest cpu users.


Top 4 highest memory users.


Memory used % and Mb, and total.
Swap used and total swap.




Hard drive space used and total space
on the partitions you configure in.







Network traffic up.
Network traffic down.


CPU & chipset temperatures & Fan speed.

Current remote connections.


Current location and weather data.



Current user's unread email.

Next is what my final finished .conkyrc looks like. It's pretty long, since I left
all the commented out keyword function descriptions in mine, so I took them
out here for sake of brevity and space. When you copy the sample file to your
home directory for editing, they'll be there and you can read and experiment
with them.

# conky configuration

# set to yes if you want Conky to be forked in the background
background no

# Use Xft?
use_xft yes

# Xft font when Xft is enabled
xftfont Terminus:size=8

# Text alpha when using Xft
xftalpha 0.8

# Print everything to console?
# out_to_console no

# mail spool
mail_spool $MAIL

# Update interval in seconds
update_interval 2.0

# This is the number of times Conky will update before quitting.
# Set to zero to run forever.
total_run_times 0

# Create own window instead of using desktop (required in nautilus)
own_window no

# Use double buffering (reduces flicker, may not work for everyone)
double_buffer yes

# Minimum size of text area
minimum_size 100 5
maximum_width 350 100
maximum_window_size 450

# Draw shades?
draw_shades yes

# Draw outlines?
draw_outline no

# Draw borders around text
draw_borders no

# Stippled borders?
stippled_borders 8

# border margins
border_margin 4

# border width
border_width 1

# Default colors and also border colors
default_color white
default_shade_color black
default_outline_color white

# Text alignment, other possible values are commented
alignment top_left

# Gap between borders of screen and text
# same thing as passing -x at command line
gap_x 800
gap_y 5

# Subtract file system buffers from used memory?
no_buffers yes

# set to yes if you want all text to be in uppercase
uppercase no

# number of cpu samples to average
# set to 1 to disable averaging
cpu_avg_samples 2

# number of net samples to average
# set to 1 to disable averaging
net_avg_samples 2

# Force UTF8? note that UTF8 support required XFT
override_utf8_locale no


# Add spaces to keep things from moving about?
This only affects certain objects.
use_spacer yes
#Note: doesn't work in conky 1.2 =(


# stuff after 'TEXT' will be formatted on screen

TEXT

${color slate grey}${time %a, } ${color }${time %e %B %G}
${color slate grey}${time %Z,      }${color }${time %H:%M:%S}
${color slate grey}UpTime: ${color }$uptime
${color slate grey}Kern:${color }$kernel
${color slate grey}CPU:${color } $cpu%
${cpugraph 15,130 000000 ffffff}
${color slate grey}Load: ${color }$loadavg
${color slate grey}Processes: ${color }$processes
${color slate grey}Running:    ${color }$running_processes

${color slate grey}Highest CPU:
${color #ddaa00} ${top name 1}${top_mem cpu 1}
${color lightgrey} ${top name 2}${top cpu 2}
${color lightgrey} ${top name 3}${top cpu 3}
${color lightgrey} ${top name 4}${top cpu 4}

${color slate grey}Highest MEM:
${color #ddaa00} ${top_mem name 1}${top_mem mem 1}
${color lightgrey} ${top_mem name 2}${top_mem mem 2}
${color lightgrey} ${top_mem name 3}${top_mem mem 3}
${color lightgrey} ${top_mem name 4}${top_mem mem 4}

${color slate grey}MEM:   ${color }   $memperc% $mem/$memmax
${membar 3,130}
${color slate grey}SWAP: ${color }    $swapperc% $swap/$swapmax
${swapbar 3,130}

${color slate grey}ROOT:   ${color }   ${fs_free /}/${fs_size /}
${fs_bar 3,130 /}
${color slate grey}HOME:   ${color } ${fs_free /home}/${fs_size /home}
${fs_bar 3,130 /home}
${color slate grey}USR:   ${color }     ${fs_free /usr}/${fs_size /usr}
${fs_bar 3,130 /usr}
${color slate grey}LOCAL:   ${color }${fs_free /usr/local}/${fs_size /usr/local}
${fs_bar 3,130 /usr/local}
${color slate grey}VAR:   ${color }    ${fs_free /var}/${fs_size /var}
${fs_bar 3,130 /var}
${color slate grey}DATA:   ${color }   ${fs_free /data}/${fs_size /data}
${fs_bar 3,130 /data}
${color slate grey}DATA2:   ${color }${fs_free /data2}/${fs_size /data2}
${fs_bar 3,130 /data2}
${color slate grey}TMP:   ${color }    ${fs_free /tmp}/${fs_size /tmp}
${fs_bar 3,130 /tmp}

${color slate grey}NET:
${color}Up: ${color }${upspeed xl0} k/s
${upspeedgraph xl0 15,130 000000 ffffff}
${color}Down: ${color }${downspeed xl0}k/s${color}
${downspeedgraph xl0 15,130 000000 ffffff}

$color orange}Chipset/CPU Temps ${hr 2}$color
${execi 60 grep temp0 /home/username/bin/sensors.out | cut -c 7-16 | fold -w50} Chipset
${execi 60 grep temp1 /home/username/bin/sensors.out | cut -c 7-16 | fold -w50} CPU
${execi 60 grep fan /home/username/bin/sensors.out | cut -c 12-15 | fold -w50} Fan Speed
${color orange}Remote Connections ${hr 2}$color
${execi 30 cat /home/username/bin/connects.out | fold -w50}
${color orange}Current Weather Conditions ${hr 2}$color
${execi 300 /home/username/bin/nwsweather.sh}
${color orange}System Messages ${hr 2}$color
username ${mails} new messages

Now for the scripts. You may have better luck using Conky's chipset functions
than I did. I just got around it with a script using 'sysctl hw.sensors' and
then cutting out what I needed and writing it to a file to be used in .conkyrc.
Here's what the script, sensors.sh, and the output, sensors.out, looks like:

sensors.sh

#!/bin/sh
#
# Monitor cpu, chipset temperatures and fan speed
#
sysctl hw.sensors | grep temp | cut -c 16-31 > /home/username/bin/sensors.out
sysctl hw.sensors | grep fan | cut -c 10-24 >> /home/username/bin/sensors.out

sensors.out

temp0=42.00 degC
temp1=30.50 degC
s.lm1.fan0=4856

I run sensors.sh from a cronjob like so:

*/2   *       *       *       *       $HOME/bin/sensors.sh > /dev/null 2>&1

You can see in the last section of .conkyrc how I pull in sensors.out info.

For the remote connections, I use another script, connects.sh:

#!/bin/sh
# Run ssh and ftp connections check
#
if netstat -a |grep ESTABLISHED
then
           netstat -a |grep ESTABLISHED |egrep 'ssh|ftp' | \
           cut -c 1-3,11-13,19-37,45-65 > \
           $HOME/bin/connects.out
else
           echo "No current connections" > $HOME/bin/connects.out
fi

And, as in the sensors output, I refresh the connections data from a cronjob:

*/2   *       *       *       *       $HOME/bin/connects.sh > /dev/null 2>&1

You can see also in the last section of .conkyrc how the connections data
is pulled in.

I got the location code for my local area for the current weather conditions
from the address in nwsweather.sh. The script looks like this:

#!/bin/sh
#
#----------------------------------------------------------------
# This script will take current ASOS observations from an
# XML file from the National Weather Service website and
# feed it to an XML stylesheet for display in the
# desktop system monitor, conky.
#----------------------------------------------------------------
# The script and xslt can be found at the following address:
# http://www.meteor.iastate.edu/~bschwedl/nwsweather.tar.gz
#----------------------------------------------------------------
# Instructions for modification of the display can be found
# throughout the files.
#----------------------------------------------------------------
# Usage:
# ${execi 1800 /path/to/weather/nwsweather.sh}
# Put this line in your .conkyrc file to update the data
# Since this data updates each hour, a 30 minutes time
# interval should be good enough to keep the data up to date.
# 1800 is the update interval in seconds.
#----------------------------------------------------------------
# Creator:        Benjamin Schwedler
# Contact:        bschwedler@gmail.com
#
# Changelog:        2007.11.27
#          File Created
#----------------------------------------------------------------

# Set your location here. The location is the Keesler Air Force Base
# code which can be found by exploring the following NWS site:
# http://www.nws.noaa.gov/data/current_obs/
#LOC="SET THIS"
LOC="KBIX"

# This is the directory where you have placed the script and
# xslt file.
#DIRPATH="SET THIS"
DIRPATH="/home/username/bin/"

# curl and xsltproc needed to properly parse the files
# http://curl.haxx.se/
# http://xmlsoft.org/XSLT/
XSLTPATH=/usr/local/bin/xsltproc
CURLPATH=/usr/local/bin/curl

# DATAXML is the page from which the observed data is fetched
DATAXML=http://www.nws.noaa.gov/data/current_obs/KBIX.xml

# Calls the xslt for parsing of the data.
# This file can be modified to display the desired output.
DATAXSLT=$DIRPATH/nwsweather.xslt

# Runs the command to parse data and display in conky
eval "$CURLPATH \"$DATAXML\" 2>/dev/null | $XSLTPATH $DATAXSLT -"

Be sure to pay attention to the line in nwsweather.sh that says curl and
xsltproc are needed for the script to work. Curl is a no brainer. You can
install it either from ports or packages. As for xsltproc, you'll need to
have libxslt installed. It's what installs xsltproc. Again, you can install
it either from ports or packages.

Some last notes:

Mail Spool:
In .conkyrc under mail spool, I tried putting in the complete path to my
mail spool, /var/mail/username, but it still wouldn't work for me. I had
to insert this into my .kshrc file:

MAIL=/var/mail/username
Then, in .kshrc in the export line, I added MAIL and made the system
reread the values:

. ./.kshrc

When I restarted conky, it was reading my mail spool okay.

tcp_portmon

This didn't work for me, I believe either because IPv6 is enabled in my
OpenBSD install, because it's disabled in the Makefile, or both. If you
get it to working with IPv6, please let me know.

Text Formatting

Throughout .conkyrc you'll have to experiment with how your information
outputs to the screen by increasing or decreasing spaces between elements.

==================================================

Addendum:
Fri Jun 6 16:28:43 CDT 2008

Since posting this write up, I've done some experimenting with getting stock
market information to display in conky. I'm using a perl script called quote
which I downloaded from:

quote -- command-line stock quote display

In my OpenBSD 4.3 system, it installed itself in /usr/local/bin. It downloads
its data from Yahoo! Finance. I added the following to the end of .conkyrc:

${color orange}Stock Market Information ${hr 2}$color
${color orange}DJIA: ${color}     ${execi 600 grep DJI /home/username/markets/markets.out |cut -c 7-32}
${color orange}NASDAQ: ${color}   ${execi 600 grep IXIC /home/username/markets/markets.out |cut -c 8-31}
${color orange}S&P: ${color}      ${execi 600 grep GSPC /home/username/markets/markets.out |cut -c 8-31}
${color orange}AMEX: ${color}     ${execi 600 grep XAX /home/username/markets/markets.out |cut -c 7-30}
${color orange}RUSSELL2K: ${color}${execi 600 grep RUT /home/username/markets/markets.out |cut -c 7-29}
${color orange}NIKKEI: ${color}   ${execi 600 grep N225 /home/username/markets/markets.out |cut -c 8-33}
${color orange}FTSE: ${color}     ${execi 600 grep FTSE /home/username/markets/markets.out |cut -c 8-31}
${color orange}10YrBond: ${color} ${execi 600 grep TNX /home/username/markets/markets.out |cut -c 7-26}
${color orange}Crude Oil: ${color}${execi 600 grep CLN08.NYM /home/username/markets/markets.out |cut -c 12-33}
${color orange}Gold: ${color}     ${execi 600 grep GCM /home/username/markets/markets.out |cut -c 12-33}
${color orange}Silver: ${color}   ${execi 600 grep SIM /home/username/markets/markets.out |cut -c 12-32}

Sorry for the long lines. They will wrap on you in a browser in a small screen and in
lynx and links, but I wanted to leave them intact as much as possible for clarity for
folks relatively new to this. Also, you may notice the uneven spacing in the code. You
will have to experiment with that just like I did to get the columns of data to line up
evenly in the display.

I wrote a script, ~/bin/myquotes.sh, to call quote to download the
data to be fed into conky. It looks like this:

#!/bin/sh
#
# run /usr/local/bin/quote to get current quotes for
# items configured below.
#
/usr/local/bin/quote '^dji' '^ixic' '^gspc' '^tnx' '^xax' '^rut' '^n225' '^ftse' cln08.nym gcm08.cmx sim08.cmx > \
/home/username/markets/markets.out

Then I call the myquotes.sh script from a cronjob:

*/10    8-15       *       *       mon-fri $HOME/bin/myquotes.sh > /dev/null 2>&1

So, the script runs every 10 minutes, Monday through Friday, during the hours between
8:00 a.m. through 3:00 p.m. since I'm in the CDT timezone, putting me an hour earlier
than the EDT timezone. You'll have to adjust yours accordingly, not that it's necessary.
It's just redundant to download data that's no longer changing. That may not apply to
some markets like the AMEX and so forth, but it's close enough for government work. :-)

Here's what the tail end of conky's display looks like, showing the stocks data:

stocks.jpg

You can look for other symbols to fit your particular stock quote needs at:

Yahoo! Finance

Cheers!

==================================================

Addendum:
Fri Jun 13 21:23:41 CDT 2008

I've got two different weather resources. One comes in the email from Accuweather and
the other is already called into conky with the script previously discussed above. I kept
wondering how I could get the email one into conky too and came up with a script that
does it for me.


#!/bin/sh

TODAYSFILE=$(ls -lt $HOME/Mail/weather/new/ |sed '1d' | \
head -n 1 | cut -c 53-94)
ANOTHERBOX=$HOME/bin/weathertoday

if ls $HOME/Mail/weather/new/*boxname* > /dev/null 2>&1

then

      cd $HOME/Mail/weather/new/ && cat $TODAYSFILE |sed '1,37d' | \
      head -n 28 > $HOME/bin/weathertoday && \
      scp $ANOTHERBOX username@anotherbox:bin/weathertoday

else

      echo "No Weather Report yet today!"

fi


The forecast isn't the only thing I get in my weather email. I also get advisories
as in the case of flash flooding, bad storms, hurricanes, and so forth. So, to make
things simple, I added a folder under $HOME/Mail called advisories and changed
my .procmailrc file to route only forecasts to $HOME/Mail/weather and the rest
to $HOME/Mail/advisories. As for the search for *boxname*, that's how mutt's
messages show up. Example:

1213353030.3994_3.boxname.someisp.net:2,S

I've got a bit of a strange setup here, in that I do a lot of experimenting on this
one old box where I'm running conky, and I get my mail on a newer box across the
room, which is why you see scp sending the formatted weather forecast text over to
another box. If you're doing everything on one box, which you probably will be, you
just chop that part off and don't worry about it. Just adjust your paths accordingly.
And, as to the paths, that's naturally dependent on your own personal configuration.

Here's what the .conkyrc section looks like now to pull in the formatted text forecast
from the other box, along with the aforementioned section earlier in this article that
gets its current conditions from the nwsweather script, and a picture of what the final
output looks like:

TEXT

${color green}Current Weather Conditions ${color}
${color yellow}${execi 1800 /home/username/bin/nwsweather.sh} ${color}
${color green}Extended Weather Forecast: ${color}
${color yellow}${execi 3600 cat /home/username/bin/weathertoday | fold -w50} ${color}

weather_219x379.png

==================================================

Addendum:
Thu Jul 3 23:47:47 CDT 2008

Currently I'm running 2 instances of conky on my desktop. One on the right
side for all pertinent system data I want to keep with like load, processes,
memory and swap usage, disk space, chipset and cpu temperatures, network
up and down activity, and local and remote users.

On the left of the screen is another instance of conky showing, from the top,
current weather conditions and a 4-day weather forecast and, during stock
market hours, a list of financial data including quotes, current commodity
prices, and exchange rates. After the stock market closes, I run a cronjob
that runs a script to kill the conky with the stock market data below the
weather data and then start conky with a different configuration showing
just the weather data. When it does that on Friday evenings, it stays that
way for the entire weekend, not reloading the stock market data again until
Monday morning. Here's what the cronjob entries look like:

31     8      *     *     mon-fri $HOME/bin/killjw.sh > /dev/null 2&>1
01     15     *     *     mon-fri $HOME/bin/killstocks.sh > /dev/null 2&>1
And, here's the 2 scripts I came up with to do the actual switching:


killjw.sh
---------


#!/bin/sh
#
# Shell script to be called from a cronjob to kill the
# conky program that runs Mon-Fri with stock updates.
# Then it starts conky with a different configuration
# to just show the current weather and forecast.
#
echo "" > ~/jwpid.out
# Make sure jwpid.out doesn't contain any data

ps -U dennyboy ¦grep justweather ¦cut -c 1-5 > ~/jwpid.out
# Search processes for my justweather conky, cut the characters
# I need for the PID number and redirect it to jwpic.out

kill `cat ~/jwpid.out`
# Feed the PID to kill. And yes, those are backticks around it.

DISPLAY=:0.0 conky -c /home/dennyboy/weathertoday.conkyrc
# Call the version of conky with the weather and stock market data
#

echo "" > ~/jwpid.out
# Once again wipe out any data in jwpid.out


killstocks.sh
-------------


#!/bin/sh
#
# Shell script to be called from a cronjob to kill the
# conky program that runs Mon-Fri with stock updates.
# Then it starts conky with a different configuration
# to just show the current weather and forecast.
#
echo "" > ~/jwpid2.out

ps -U dennyboy ¦grep weathertoday ¦cut -c 1-5 > ~/jwpid2.out

kill `cat ~/jwpid2.out`

DISPLAY=:0.0 conky -c /home/dennyboy/justweather.conkyrc

echo "" > ~/jwpid2.out


If you look back in this article and search for weathertoday, you'll see
it in quite a few places. That's what I named that conky config file long
before I ever learned how to add the stock market stuff to it. Afterwards,
I just never bothered to change the scripts and rename the file. So now it
looks kind of weird, but don't pay any attention to that. That's just the
result of my laziness and procrastination. Use your imagination and name
your files whatever you want.

I also did some work on my ~/.xinitrc file so both instances of conky
would start when I start my X desktop, and the one on the left would know
which configuration to use depending on the time of day and the day of the
week. Here are the pertinent entries:


.xinitrc snippet
-------------


. ~/./.kshrc
# Previous command clears the environment of stale entries.
CONKYTIMES=$(date |cut -c 12,13)
# Run date and cut out everything except the what hour of the day it is
# and assign that value to CONKYTIMES.
export CONKYTIMES
# Export the value for CONKYTIMES to the enviroment.
# All of the above is right at the beginning of my .xinitrc file.
#
# What follows is inserted right before the command to load fluxbox.
# The file ~/conkytimes is just a plaintext file with acceptable
# hour values when the conky configuration with stock market data
# should be run. If the script gets a negative return, it knows to
# run the other configuration with just the weather.
#
if [ grep `echo $CONKYTIMES` ~/conkytimes ]; then
conky -c weathertoday.conkyrc &
else
conky -c justweather.conkyrc &
fi
conky -c combo.conkyrc &
fluxbox


This what ~/conkytimes looks like:
08
09
10
11
12
13
14

So, if grep finds the $CONKYTIME value in that file, it loads conky with
the stock market data below the weather data. If it doesn't find it, it
loads just the weather version of the file.

IMPORTANT!
If you notice, in .xinitrc there isn't any DISPLAY:0.0 before the conky
commands like there is in the scripts above that are run from a cronjob.
The keyword is cronjob. Before I put the DISPLAY info in the scripts,
conky would not load correctly from the cronjob like it does when it's
run from .xinitrc, from an xterm, or from a fluxbox menu entry. Don't
be confused, either, by the other conky entry after fi. That's just the
the other instance of conky running on the right side of the screen.
And, remember if you're going to run multiple instances of conky, you
will probably have to change your conky configuration files to:
double_buffer no
Otherwise they'll fight each other and probably just keep blinking on
and off. At least that's what mine did. But, I'm running a really old
home-built box with an ancient Voodoo video card. YMMV! Cheers!

==================================================

Addendum:
Sat Jul 19 14:48:47 CDT 2008

For Mutt Users

I recently moved all my mutt stuff over to an older box I use quite a bit
but, up until now, not for email except for system messages. And that's
when I saw that the old way I'd used for displaying system mail in conky
wasn't going to work, since previously I'd been using pine for my email.
Pine doesn't take it's mail from /var/mail/user until you actually open
pine, whereas when I download my messages with getmail for mutt to
access, the messages are already 'in' mutt, literally. So the old way of
using the conky built-in function {mails} wasn't going to work for me.
I had to come up with a new way. At first I thought about using a script,
but then realized I was just complicating things. Instead, I added lines
for my most read folders in mutt into my conkyrc file like so:

${color yellow}root ${execi 60 ls -lt Mail/root/new ¦sed &¡1d¡ ¦wc -l cut -c 7-8} ${color}

In the example above, after root, which is a folder inside of ~/Mail, the
command sequence begins with ${execi}, and that's where you'll have to
play around with the spacing between them to get them to line up nicely
on your screen.

==================================================

Addendum:
Wed Jul 23 18:47:14 CDT 2008

NOAA Script Problems

Since yesterday, my script, nwsweather.sh, written about way earlier in this
article, is giving parsing error messages when it runs, so apparently they've
changed something in their xml stuff at their site, National Weather Service.

So, until I find out what's going on there, I've come up with an alternative.
In order to make it work, the first thing you have to do is go there and find
out the address for your current weather conditions. It's at:

XML Feeds of Current Weather Condtions

Click the arrow, choose your state, then click find. When you get the results,
hold your mouse pointer over the appropriate rss icon and write down the URL.
You'll need it to use wget to get the file. Mine is at Keesler Air Force Base
which shows up as KBIX which you'll see in the script. Let me say before I even
show the script that it's ugly but it works. I was really aggravated with the
situation since it had all worked so well for so long, and hurried and kludged
it together to get it working again. I'm sure someone out there can figure out
how to simplify it and all suggestions will, as always, be welcome. Here's what
it came out look like:

#!/bin/sh
#
cd /home/user/bin
wget http://www.weather.gov/xml/current_obs/KBIX.rss
#
cat KBIX.rss ¦sed -e 's#<[^>]*>##g' ¦sed 's/\&quot\;/"/g' > KBIX.rss.out
tr ')' '\012' < KBIX.rss.out ¦sed 's/mb/mb)/' ¦sed '1,20d' > KBIX.rss.2out
mv -f KBIX.rss last.KBIX.rss
#
echo =============================== > KBIX.rss.3out
echo >> KBIX.rss.3out
head -n 1 KBIX.rss.2out ¦sed 's/Keesler Air Force Base/KAFB/' ¦ \
tr '/' '\012' ¦head -n 1 >> KBIX.rss.3out
#
cat KBIX.rss.2out ¦sed '1,4d' ¦head -n 1 ¦tr 'H' '\012' ¦ \
sed 's/MP/MPH/' ¦head -n 1 >> KBIX.rss.3out
#
cat KBIX.rss.2out ¦sed '1,4d' ¦head -n 1 ¦tr 'H' '\012' ¦ \
sed '1d' ¦cut -c 4-38 >> KBIX.rss.3out
#
grep humidity KBIX.rss.2out ¦cut -c 2-24 >> KBIX.rss.3out
#
grep "heat index" KBIX.rss.2out ¦cut -c 10-29 >> KBIX.rss.3out
grep "Last Updated" KBIX.rss.2out ¦cut -c 10-44 >> KBIX.rss.3out
echo >> KBIX.rss.3out

And here's what the final output looks like:

conky_202x100.jpg

I dressed up the output a little with all the equal signs and other places with
sending an empty echo line to the output file to keep it consistent with other
conky stuff on my desktop. Also with all the other tr, cut, and head stuff. You
will have to experiment to get it to look neat with the data you download for
your particular weather area. I should also mention I put in a full path to my
bin directory for example. You might not have a lot of scripts and run them
right from the root of your home directory. I've got a lot and a lot of them like
this one output other files. I don't like to clutter up my home directory. It's
already cluttered enough from my experimenting all the time.

==================================================

Addendum:
Sun Jul 27 22:02:03 CDT 2008

In my on going battle to keep conky working with the weather site data, I did
not notice that from time to time, the intial line changes to something other
than something having to do with MPH. This evening is a good example. The
first line is "Heavy Rain/Mist and 75 degrees F at KAFB". I thought about
it for a while and saw where the common element was KAFB, so I rewrote the
script like so:

#!/bin/sh
#
cd /home/user/bin
wget http://www.weather.gov/xml/current_obs/KBIX.rss
#
cat KBIX.rss ¦sed -e 's#<[^>]*>##g' ¦sed 's/\&quot\;/"/g' > \
KBIX.rss.out
#
tr ')' '\012' < KBIX.rss.out ¦sed 's/mb/mb)/' ¦sed '1,20d' > KBIX.rss.2out
#
mv -f KBIX.rss last.KBIX.rss
#
echo =============================== KBIX.rss.3out
#
echo >> KBIX.rss.3out
#
head -n 1 KBIX.rss.2out ¦sed 's/Keesler Air Force Base/KAFB/' ¦ \
sed 's/KAFB \/ Biloxi, MS/KAFB/' >> KBIX.rss.3out
#
cat KBIX.rss.2out ¦sed 's/\./?/' ¦tr '?' '\012' ¦ \
sed 's/^[ \t]*//;s/[ \t]*$//' ¦sed '/^$/d' ¦tail -n 6 ¦ \
head -n 5 >> KBIX.rss.3out
#
echo >> KBIX.rss.3out
#
cd

As long as the weather site changes the format, I guess you have to keep on
adapting accordingly. Hopefully, though, this one might be a keeper. Yeah,
right! :-) Cheers!

==================================================

Addendum:
Fri Jan 23 21:14:23 CST 2009

After writing the above aforementioned scripts to be called from a cronjob
to rotate the version of .conkyrc I needed to use depending on the time of
day or day of week, I found that the scripts were hanging in memory for a
long time after doing their jobs, so I revised the scripts to looks like this:

killjw.sh
---------


#!/bin/sh
# File name: killjw.sh
# Shell script to be called from a cronjob to kill the
# conky program that runs nightly, Mon-Fri, and weekends,
# displaying weather info, and then open the conky config
# that displays stock updates and weather information.

if ps -U dennyboy ¦grep justweather;

then

          echo "" > /home/dennyboy/jwpid.out
          ps -U dennyboy ¦grep justweather ¦ \
          cut -c 1-5 > /home/dennyboy/jwpid.out
          kill `cat /home/dennyboy/jwpid.out`
          DISPLAY=:0.0 exec conky -c /home/dennyboy/weathertoday.conkyrc
          echo "" > /home/dennyboy/jwpid.out

else

          echo "No instances of conky appear to be running!"

fi

On the line that starts with DISPLAY, notice the exec switch. That's what
keeps my script from hanging. Compare this version of the script to the one
further up the page and notice the differences. Also, justweather used above
and weathertoday used in the next script refer to the prefixes prepended to
their particular .conkyrc file. For example, justweather.conkyrc.

killstocks.sh
-------------


#!/bin/sh
# File name: killstocks.sh
# Shell script to be called from a cronjob to kill the
# conky program that runs Mon-Fri with stock updates.
# Then it starts conky with a different configuration
# to just show the current weather and forecast.

if ps -U dennyboy ¦grep weathertoday;

then

          echo "" > /home/dennyboy/jwpid2.out
          ps -U dennyboy ¦grep weathertoday ¦ \
          cut -c 1-5 > /home/dennyboy/jwpid2.out
          kill `cat /home/dennyboy/jwpid2.out`
          DISPLAY=:0.0 exec conky -c /home/dennyboy/justweather.conkyrc
          echo "" > /home/dennyboy/jwpid2.out

else

          echo "No instances of conky appear to be running!"

fi

I hope no one else ran into the same problem using my earlier examples,
but it's probably very possible they did. Hopefully this will rectify that.

Cheers!

==================================================

Addendum:
Thu Nov 5 22:16:37 CST 2009

First off, the old problem of the two different versions of conky not
starting properly never completely went away. I just didn't have time
to do much work on the site lately. The previous way is listed directly
above this addendum. I read up some more on X and especially on
xwininfo(1). The first line of output of xwininfo -root gave me this:

xwininfo: Window id: 0x46 (the root window) (has no name)

In the script that gets called from a cronjob, I use the following method
to kill the current instance of Conky that's running:

ps -U useracct ¦grep weathertoday.conkyrc |awk '{print $1}' ¦ \
xargs kill -15


Addendum:
Mon Jan 11 10:50:12 CST 2010

Someone was kind enough to point out to me it is easier to kill the
instance of Conky running like so:

pkill -f weathertoday.conkyrc

Then, the new way I use to start the different version of Conky is:

DISPLAY=:0.0 /usr/local/bin/conky -w 0x46 -c justweather.conkyrc

As always, I hope what I'd put before didn't cause too many problems for
anyone, and I hope this way makes it easier for anyone who is having the
the same problem I was.

Cheers!

Back to Tips and Tricks
Home


Delicious Bookmark this on Delicious

No affiliation between this site and the OpenBSD project exists or is implied.

valid-html401.png