The following script is intended to run on your file server that collects data to distribute to your network. Safety is built in to prevent contacting NOAA weather.gov more than one time per hour. The data comes in .xml format and contains the recommended time to collect the data, per each region. Information on what files to request can be found by much digging and a visit to XML Feeds of Current Weather Conditions https://w1.weather.gov/xml/current_obs/ and NWS Public Alerts in XML/CAP and ATOM Formats https://alerts.weather.gov/ combined with close attention to the browser URL when you look at your weather on weather.gov.
#!/bin/bash # pull weather from weather.gov # But ONLY IF it has not been pulled recently # weather is updated once per hour & recommended time to pull is hour+15 # program cron accordingly # last_update: 20170826 JDN # PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin # define minimum time lapse before new pull is permitted declare -i MINAGE=22 echo 'Min age' $MINAGE # calculate time lapsed since last pull if [ -f wwraw.xml ]; then declare -i LAPSE=$(( ( $(date +%s) - $(stat wwraw.xml -c %Y)) / 60 )) echo 'Lapse' $LAPSE else declare -i LAPSE=999 fi # allow override of command line parameter #1 is --force if [ -n "$1" ]; then declare -i FORCE=1; else declare -i FORCE=0; fi echo force is $FORCE #log outside IP echo "OpenDNS/Google" $(dig +short myip.opendns.com @resolver1.opendns.com) / $(dig TXT +short o-o.myaddr.l.google.com @ns1.google.com) >wwraw.xme # calculate if pull is permitted (boolean) DOPULL=$(( $LAPSE >= $MINAGE )) echo dopull is $DOPULL # test time lapse vs. minimum time lapse to allow pull or override # Check if file older if [[ $(($DOPULL + $FORCE)) -gt 0 ]]; then # debugging message output if pull was performed echo "File was pulled $LAPSE minutes ago. Pulling new weather data" # get surface observations # file will have date / time from weather.gov wget -q --output-document="wwraw.xml" http://w1.weather.gov/xml/current_obs/KFWA.xml # mark file with current time to prevent hammering weather.gov touch wwraw.xml # get weather alerts wget -q --output-document="walerts.xml" http://alerts.weather.gov/cap/wwaatmget.php?x=INC003&y=0 else # debugging message output if pull was not performed echo "File was pulled $LAPSE minutes ago. Ignoring request to pull again." fi #cleanup unset FORCE unset DOPULL unset MINAGE unset LAPSE exit 0
You must be logged in to post a comment.