-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathoffbattery
49 lines (43 loc) · 1.09 KB
/
offbattery
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
#!/bin/sh
#
# This shell script if placed in /etc/apcupsd
# will be called by /etc/apcupsd/apccontrol when the
# UPS goes back on to the mains after a power failure.
#
HOSTNAME=`hostname`
MSG="$HOSTNAME UPS $1 Power has returned"
MGMT_BOT_ID=""
CLUBWIDE_BOT_ID=""
GROUPME_API_URL="https://api.groupme.com/v3/bots/post"
if [ -f fifteen.pid ]; then
PID=$(cat fifteen.pid)
kill $PID
if [ $? -eq 0 ]; then
echo "Process $PID stopped."
rm fifteen.pid
else
echo "Failed to stop process $PID."
fi
else
echo "PID file not found."
fi
(
echo "To: $SYSADMIN"
echo "From: wbor-smtp@bowdoin.edu"
echo "Subject: $MSG"
echo ""
echo "Back in action!"
) | sudo $APCUPSD_MAIL $SYSADMIN
curl -s -X POST $GROUPME_API_URL \
-H "Content-Type: application/json" \
-d '{
"text": "!!!\n\n'"$MSG"'\n\nPower has been restored!",
"bot_id": "'"$MGMT_BOT_ID"'"
}'
curl -s -X POST $GROUPME_API_URL \
-H "Content-Type: application/json" \
-d '{
"text": "Power is back!",
"bot_id": "'"$CLUBWIDE_BOT_ID"'"
}'
exit 0