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 and use the URL in the script.


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!
        # commands to run if temperature is less than threshold
        echo It's just right.
    sleep $PERIOD

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

Loading Conversation