forked from Sirus10/domoticz
-
Notifications
You must be signed in to change notification settings - Fork 0
/
alert_gel.sh
81 lines (71 loc) · 2.78 KB
/
alert_gel.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#!/bin/sh
#
########################################################################################
# This script aim will alert by mail if temperature
# will be lower than x °C in the comming days
#
# Site : http://domotique.web2diz.net/
# Details : http://domotique.web2diz.net/?p=859
# Source : https://github.com/Sirus10/domoticz/blob/master/get_rain_probability.sh
# License : CC BY-SA 4.0
#
# Usage:
# ./alert_get <city>
# EX : ./alert_gel Montpellier
#
# Daily scheduling in crontab :
# 30 7 * * * /root/scripts/alert_gel.sh Toulouse > /tmp/probal_gelToulouse.log
#
#######################################################################################
# Setup the default city,
CITY=Toulouse # Default city is $1 not set
# Alert in case of lower temp than tempAler.
# If you wahtn be alerte if tempterature lwill be lower than 3° set : tempAler=3
tempAlert=3
APIKEY=your_wunderground_apiKEY
sender="From: Pedro <[email protected]>"
if [ "$1" != '' ] ; then
CITY=$1
fi
kill -9 `ps -ef | grep prevision | grep -v grep |grep -v $$ | awk '{print $2}'`
# Download forecass for next 10 days
curl -f "http://api.wunderground.com/api/$APIKEY/forecast10day/lang:FR/q/France/"$CITY".xml" -o /tmp/weather$CITY-10D.out
echo "############ Risque de gel ###############"
echo "########## "`date`" ##########"
echo " Temp mini dans les 10 jours a venir : "
tempsmini=`/usr/bin/xml_grep 'low/celsius' /tmp/weather$CITY-10D.out --text_only`
i=0
sentmail=0
for t in $tempsmini; do
echo "Dans $i jour(s) : $t °C à $CITY"
#val=$val"Dans $i jours : $t °C <br>\n"
if [ $t -lt $tempAlert ]
then
echo "---------------------------> Risque de gel dans $i jour(s) ! "
alert=" --> <b> Risque de gel dans $i jours ! </b>"
if [ $sentmail -eq 0 ]
then
MESS="Risque de Gel Dans $i jours : $t °C à $CITY"
SUB="Risque de Gel dans $i jours"
SUB=`echo $SUB |sed 's/0 jours/les 24h/g'`
SUB=`echo $SUB |sed 's/1 jours/1 jour/g'`
sentmail=1
fi
else
alert=""
fi
val=$val"Dans $i jours: $t °C "$alert"<br>"
i=$(($i + 1))
done
val=`echo $val |sed 's/0 jours/les 24h/g'`
val=`echo $val |sed 's/1 jours/1 jour/g'`
echo "#####################################"
echo $val
echo "#####################################"
# Envois du mail si besoin
if [ $sentmail -eq 1 ]
then
echo "Envoi du mail d'alerte "
echo "Prevision à venir à $CITY (Minimales) <br> $val <br><center><small>Weather forecast from wunderground.com</small></center>" | mail -a "$sender" -s "$(echo "$CITY : $SUB\nContent-Type: text/html")" $recipient
fi