1#! /bin/bash
2
3# Send warning email on power loss. Triggered by pwrstatd.
4# Andrew Lorimer, January 202t
5
6recipient="andrew"
7
8ctime=`date`
9state=`pwrstat -status`
10model=`echo $state | grep -oP 'Model Name\.+ \K\w+'`
11runtime=`echo $state | grep -oP 'Remaining Runtime\.+ \K\d+\s?\w+(?=\.)?'`
12
13echo -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