From: Andrew Lorimer Date: Tue, 21 Jan 2020 11:37:07 +0000 (+1100) Subject: Merge branch 'master' of /tank/andrew/code/scripts X-Git-Url: https://git.lorimer.id.au/scripts.git/diff_plain/c813b7d737df45ad4f14e24c10b3be8200788986?hp=5076ca44d79d7479b36556aba83076a75269f727 Merge branch 'master' of /tank/andrew/code/scripts --- 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