MLUG Bash Scripting Workshop 25/04/08
Prev Index Next

Note that the Australian BOM has changed the layout of their website so that the script discussed here and on the next two pages will no longer work. I'll leave these pages "as is" for anyone interested. There is a newer verison of this script that works with the new BOM website that can be found here.


Piping the weather in a Bash script

It's impossible to hear a weather forecast on the radio when you want one. The BOM's website is great but to get there I have to open a browser and point and click my way to the weather for my locality.

My get-forecast script gives us the most recent Mornington Penninsula weather forecast in .35 to .45 of a second after I type get-forecast and hit enter

This will be the last section of this presentation and I thought you might like to customise this script for your locality. I'll give you a screenshot and the relevant section out of the script below and then I'll explain how it works and how you can modify get-forecast for your own local forecast.


# Provide date, time, etc. but use echo so we don't return to a prompt	
 echo -e "`date`\n"

 # Pipe webpage from lynx to grep and get the date/time issued

 lynx -dump www.bom.gov.au/cgi-bin/wrap_fwo.pl?IDV17102.txt | grep Issued

 # Make some space

 echo ""

 # Pipe webpage from lynx to sed
 # Use sed to get everything after Mornington and pipe it to sed which removes
 # everything after [27] and pipes what's left to more.
 # More is used to display text in the terminal.

 lynx -dump www.bom.gov.au/cgi-bin/wrap_fwo.pl?IDV17102.txt | \
 sed -n '/Mornington/,/\[27\]/ p' | sed -e '/\[27\]/ d' | more 

 # Uncomment the following line if you have  BSD-games pom installed
 # and you want to include the current phase of the moon.
 echo -e "`pom` \n\n"


Top