-
Notifications
You must be signed in to change notification settings - Fork 2
/
nutNotifyBoot.sh
59 lines (49 loc) · 1.63 KB
/
nutNotifyBoot.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
#!/bin/bash
# variables
configFile=/usr/local/etc/nutNotify.conf
source "$configFile"
source "$(dirname $0)/nutNotifyFct.sh"
if [ ! -e "$configFile" ] ; then
echo "File $configFile doesn't exist" 1>&2
exit 1
fi
function aide() {
echo "$0 [mail|pushbullet|telegram]"
}
# verify method
if [ $# == 0 ] ; then
if [ ! -x $mailBin ] ; then
echo "No mail command found at $mailBin, you need to install bsd-mailx!" 1>&2
exit 1
fi
notifynut_method=mail
elif [ $# == 1 ] ; then
if [ "$1" == "mail" ] && [ ! -e $mailBin ] ; then
echo "Error $BIN_MAIL not found" 1>&2 && exit 1
elif [ "$1" == "pushbullet" ] && [ ! -x $curlBin ] && [ "$pushbulletAccessToken" != "" ] ; then
echo "Error pushbullet not configured" 1>&2 && echo "Error telegram not configured" > $logfile && exit 1
elif [ "$1" == "telegram" ] && [ ! -x $curlBin ] && [ "$telegramAccessToken" != "" ] && [ "$telegramChatID" != "" ] ; then
echo "Error telegram not configured" 1>&2 && echo "Error telegram not configured" > $logfile && exit 1
elif [ "$1" == "mail" ] || [ "$1" == "pushbullet" ] || [ "$1" == "telegram" ] ; then
notifynut_method="$1"
else
aide
fi
else
echo "Error the method $1 is not supported"
fi
text="$(date '+%d/%m/%y %H:%M:%S') $HOSTNAME booting\n Downtime $(date -d @$(( $(date +'%s') - $(cat $flagfile))) -u +%H:%M:%S)"
if [ -e $flagfile ] ; then
case "$notifynut_method" in
mail)
sendMail "$subjectMail" "$text" ;;
pushbullet)
sleep 30; sendPushBullet "$pushbulletSubject" "$text" ;;
telegram)
sleep 30; sendTelegram "$text" "$telegramSubject" ;;
pushover)
sleep 30; sendPushover "$text" "$pushoverSubject" ;;
esac
rm $flagfile
fi
exit 0