31 lines
1.1 KiB
Bash
Executable File
31 lines
1.1 KiB
Bash
Executable File
#!/bin/bash
|
|
#
|
|
# NUT NOTIFYCMD script macester macecapri@gmail.com
|
|
PATH=/sbin:/usr/sbin:/bin:/usr/bin:/usr/local/sbin:/usr/local/bin
|
|
|
|
BATTERYLEVEL=20
|
|
|
|
trap "exit 0" SIGTERM
|
|
if [ "$NOTIFYTYPE" = "ONLINE" ]
|
|
then
|
|
echo $0: power restored | wall
|
|
/usr/local/emhttp/plugins/dynamix/scripts/notify -e "UPS Notification" -s "UPS is no longer on battery" -i "normal"
|
|
# Cause all instances of this script to exit.
|
|
killall -s SIGTERM `basename $0`
|
|
fi
|
|
if [ "$NOTIFYTYPE" = "ONBATT" ]
|
|
then
|
|
echo $0: System shuts down when battery reaches $BATTERYLEVEL % | wall
|
|
/usr/local/emhttp/plugins/dynamix/scripts/notify -e "UPS Notification" -s "UPS is on battery" -i "alert"
|
|
# Loop with one second interval to allow SIGTERM reception.
|
|
timer=$( /usr/bin/upsc ups|grep battery.charge:|awk '{print $2}' )
|
|
while [ $timer -gt $BATTERYLEVEL ]
|
|
do
|
|
sleep 1
|
|
timer=$( /usr/bin/upsc ups|grep battery.charge:|awk '{print $2}' )
|
|
done
|
|
echo $0: commencing shutdown | wall
|
|
/usr/local/emhttp/plugins/dynamix/scripts/notify -e "UPS Notification" -s "UPS is shutting down unRAID" -i "alert"
|
|
upsmon -c fsd
|
|
fi
|