#!/bin/bash - # $Author: jeffr $ # $Date: 2023-12-16 08:53:50 -0500 (Sat, 16 Dec 2023) $ # $Revision: 3 $ # Make sure latitude and longitude have been provided if [ $# -ne 2 ] ; then echo Usage $0 latitude longitude exit 1 fi # Create some temp files for the data temp1=$(mktemp /tmp/weather.XXXXXXXXX) temp2=$(mktemp /tmp/weather.XXXXXXXXX) temp3=$(mktemp /tmp/weather.XXXXXXXXX) temp4=$(mktemp /tmp/weather.XXXXXXXXX) temp5=$(mktemp /tmp/weather.XXXXXXXXX) temp6=$(mktemp /tmp/weather.XXXXXXXXX) # Get the weather content lynx -dump -nolist http://forecast.weather.gov/MapClick.php?lat=$1\&lon=$2> $temp1 # Check to see if the latitude/longitude was valid if [ $(grep -c "unavailable for the requested location" $temp1) -gt 0 ] ; then echo "Couldn't get weather for the specified latitude/longitude ($1/$2). Quitting." rm $temp1 $temp2 $temp3 exit 1 fi # Get number of lines in the file no_lines=$(wc -l $temp1 | awk -F" " '{ print $1 }') # Process the top of the weather content tail_line=$(grep -n "Current conditions at" $temp1 | awk -F":" '{ print $1 }') tail_val=$(( $no_lines - $tail_line + 1)) tail -n $tail_val $temp1 | less > $temp2 # Process the bottom of the weather content head_line=$(grep -n "Additional Forecasts and Information" $temp2 | awk -F":" '{ print $1 }') head_val=$(( $head_line - 1)) head -n $head_val $temp2 > $temp3 # Remove unnecessary lines sed '/More Information:*/d' $temp3 > $temp4 sed '/Local Forecast Office*/d' $temp4 > $temp5 sed '/Weather Forecast*/d' $temp5 > $temp6 # Add a header and output the result echo Weather generated $(date) by $(whoami)@$(hostname). ; echo cat $temp6 # Clean up rm $temp1 $temp2 $temp3 $temp4 $temp5 $temp6