Skip to content

Instantly share code, notes, and snippets.

@RobCranfill
Last active May 24, 2024 16:25
Show Gist options
  • Select an option

  • Save RobCranfill/e7f2af589d73af09b63259058811dc49 to your computer and use it in GitHub Desktop.

Select an option

Save RobCranfill/e7f2af589d73af09b63259058811dc49 to your computer and use it in GitHub Desktop.
#!/bin/bash
# check the weather station's battery by screen-scraping the WeeWX main page
# and send a status email
WX_URL="http://pi4.local/weather"
MAIL="/home/rob/.local/bin/cransend.sh"
EMAIL_TO="[email protected]"
TEMP_FILE="/tmp/checkWxBatt.html"
wget --quiet $WX_URL --output-document=$TEMP_FILE
if [ $? -ne 0 ]; then
logger -s "$0: Cannot reach weather station at $WX_URL"
echo "Cannot reach weather station at $WX_URL" | $MAIL -s "Weather station unresponsive" $EMAIL_TO
exit 1
fi
RESULT="`grep Transmitter -A 1 $TEMP_FILE | awk -F '[<>]' '{print $5}' | tr -d '\n'`"
# echo "!$RESULT!"
DATE=`date`
if [ "$RESULT" = "OK" ]; then
logger -s "Battery is OK."
echo "Weather station battery is OK on $DATE" | $MAIL -s "Weather station battery OK" $EMAIL_TO
else
logger -s "Battery is low!"
echo "Weather station battery is low on $DATE" | $MAIL -s "Weather station battery low" $EMAIL_TO
fi
rm $TEMP_FILE
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment