-
Notifications
You must be signed in to change notification settings - Fork 1
/
upsreset.sh
executable file
·59 lines (52 loc) · 1.34 KB
/
upsreset.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
# Manually configured script to power cycle a port on a hub that supports PPPS
CONFIG="/etc/sysconfig/trippfix"
PORT=""
TRIPPID="09ae:3016" # Tripplite SMART1500LCDT
HUBID="0409:0058" # Linksys USB2HUB4
DELAY="10"
CONTACT=""
test -s "$CONFIG" && . "$CONFIG"
reset() {
port="$1"
if test -z "$port"; then
logger -t upsreset "PORT not set in $CONFIG"
return 1
fi
# Find Linksys USB2HUB4
lsusb | grep "$HUBID" |
while read x1 bus x2 dev x3; do
let bus="$bus"
let dev="${dev%:}"
# echo $bus $dev
logger -t upsreset "Turning off port $port on ${bus}:${dev}"
/sbin/hub-ctrl -b "${bus}" -d "${dev}" -P "$port" -p 0
sleep "$DELAY"
logger -t upsreset "Turning on port $port on ${bus}:${dev}"
/sbin/hub-ctrl -b "${bus}" -d "${dev}" -P "$port" -p 1
done
}
if [ "$1" = "-r" ]; then
reset "$PORT"
exit
fi
set - `tail -1 /var/log/ups.log`
event="$3"
shift 3
msg="$*"
if [ "$event" = "NOCOMM" ]; then
if lsusb | grep "$TRIPPID" >/dev/null; then
logger -t upsreset "UPS $TRIPPID active on USB"
else
logger -t upsreset "RESET UPS $TRIPPID"
reset "$PORT"
fi
elif [ "$event" = "SMS" ]; then
logger -t upsreset "UPS SMS $msg"
if test -n "$CONTACT"; then
echo "$msg" | sms stuart
else
logger -t upsreset "CONTACT not set in $CONFIG"
exit 1
fi
fi