counter=1
text_minutes_ago=" minutes ago"
while [ $counter -lt 30 ]
do
if [ $counter -eq 1 ]; then
priortime=$(date -u -d '1 minute ago' +"%Y_%m_%d_%H_%M")
else
textpriortime="${counter}S{text_minutes_ago}"
priortime=$(date -u -d "$textpriortime" +"%Y_%m_%d_%H_%M")
fi
thistimeexists=$(curl -s --max-time +2 --head "https://weather.gc.ca/data/radar/detailed/temp_image/WSO/WSO_PRECIP_SNOW_${priortime}.GIF" | head -n 1 | grep "HTTP/1.[01] [23]..")
if [ x"${thistimeexists}" = x"" ]; then
wget "https://weather.gc.ca/data/radar/detailed/temp_image/WSO/WSO_PRECIP_SNOW_${priortime}".GIF"
else
counter = 100
fi
counter=$((counter+1))
done