This script periodically checks the outdoor temperature from Accuweather and performs runs commands based on whether the temperature is above or below the threshold. Look up your location at accuweather.com and use the URL in the script.

#!/bin/sh

URL='http://www.accuweather.com/en/us/new-york-ny/10001/weather-forecast/349727'
THRESHOLD='80' # temperature threshold in degrees F
PERIOD='30m'   # how often to check
while true; do
    temp=$(wget -q -O- "$URL" | awk -F\' '/acm_RecentLocationsCarousel\.push/{print $10 }'| head -1)
    echo $temp
    if [ "$temp" -ge "$THRESHOLD" ]; then
        # commands to run if temp is greater than or equal to threshold
        echo It's too hot!
    else
        # commands to run if temperature is less than threshold
        echo It's just right.
    fi
    sleep $PERIOD
done

The temperature extraction method is adapted from Florian Diesch's response to a question on Ask Ubuntu.


Loading Conversation