From: Andrew Lorimer Date: Tue, 21 Jan 2020 11:37:03 +0000 (+1100) Subject: add pwrstatd scripts for UPS X-Git-Url: https://git.lorimer.id.au/scripts.git/diff_plain/7ebedd5ffad78ea39b85ea2996eb2d7a5b7dfdf2?ds=inline;hp=--cc add pwrstatd scripts for UPS --- 7ebedd5ffad78ea39b85ea2996eb2d7a5b7dfdf2 diff --git a/pwrstatd-lowbatt.sh b/pwrstatd-lowbatt.sh new file mode 100755 index 0000000..4c59cfb --- /dev/null +++ b/pwrstatd-lowbatt.sh @@ -0,0 +1,18 @@ +#! /bin/bash + +# Send warning email and shut down system when UPS battery is low. +# Andrew Lorimer, January 2020 + +recipient="andrew" + +ctime=`date` +state=`pwrstat -status` +model=`echo $state | grep -oP 'Model Name\.+ \K\w+'` +runtime=`echo $state | grep -oP 'Remaining Runtime\.+ \K\d+\s?\w+(?=\.)?'` +level=`echo $state | grep -oP 'Battery Capacity\.+ \K\d+'`"%" + +echo -e "Battery level is $level (expected runtime $runtime) as of $ctime. Shutting down system in one minute.\n$state" | mail -a "Importance: High" -a "Content-Type: text/plain; charset=UTF-8" -s "⚠️🔋 Battery level $level on $model" $recipient +sleep 60 + +echo "Starting system shutdown due to low battery" | systemd-cat -t `basename "$0"` +shutdown now diff --git a/pwrstatd-powerfail.sh b/pwrstatd-powerfail.sh new file mode 100755 index 0000000..65ea690 --- /dev/null +++ b/pwrstatd-powerfail.sh @@ -0,0 +1,13 @@ +#! /bin/bash + +# Send warning email on power loss. Triggered by pwrstatd. +# Andrew Lorimer, January 202t + +recipient="andrew" + +ctime=`date` +state=`pwrstat -status` +model=`echo $state | grep -oP 'Model Name\.+ \K\w+'` +runtime=`echo $state | grep -oP 'Remaining Runtime\.+ \K\d+\s?\w+(?=\.)?'` + +echo -e "Mains power was lost at $ctime. Expected runtime is $runtime.\n$state" | mail -a "Importance: High" -a "Content-Type: text/plain; charset=UTF-8" -s "⚠️🔌 Power failure on $model" $recipient