Here are my APCUPSD Custom Scripts - all use the âMail serviceâ menu that writes inside config file
/var/ipfire/dma/mail.conf the SENDER and RECIPIENT of Mail Service
changeme script - used to signal Battery needs to be replaced
#!/bin/sh
#
# This shell script if placed in /etc/apcupsd
# will be called by /etc/apcupsd/apccontrol when apcupsd
# detects that the battery should be replaced.
# We send an email message to root to notify him.
#
mailfile="/var/ipfire/dma/mail.conf"
if [ -f $mailfile ]; then
FROM=`grep -a SENDER $mailfile | cut -f2 -d=`
TO=`grep -a RECIPIENT $mailfile | cut -f2 -d=`
else
exit
fi
MSG="$HOSTNAME UPS $1 battery needs changing NOW!!!"
#
apcaccess status > /var/log/apcupsd.status
BATTDATE=`grep -a BATTDATE /var/log/apcupsd.status | cut -f2 -d:`
time=`grep -a TIMELEFT /var/log/apcupsd.status | cut -f2 -d:`
statusdate=`grep -a "END APC" /var/log/apcupsd.status | cut -f2,3,4 -d:`
battery=`grep -a BCHARGE /var/log/apcupsd.status | cut -f2 -d:`
load=`grep -a LOADPCT /var/log/apcupsd.status | cut -f2 -d:`
voltage=`grep -a LINEV /var/log/apcupsd.status | cut -f2 -d:`
timeonbattery=`grep -a CUMONBATT /var/log/apcupsd.status | cut -f2 -d:`
systemdate=`date "+%a, %e.%m.%Y %H:%M:%S"`
BATTV=`grep -a BATTV /var/log/apcupsd.status | cut -f2 -d:`
(
echo From: $FROM
echo To: $TO
echo Subject: "$MSG"
echo ""
echo $MSG
echo ""
echo "Battery Install Date: "$BATTDATE
echo "Battery Voltage: "$BATTV
echo "Time left: "$time
echo "Cummulated time on battery: "$timeonbattery
echo "Battery Charge level and Nominal Voltage: "$battery
echo "Load: "$load
echo "Voltage: "$voltage
echo "UPS report time: "$statusdate
echo ""
echo "Full UPS Status follows:"
apcaccess status
)| sudo -u nobody /usr/sbin/sendmail -t -f $FROM
exit 0
onbattery used to signal when UPS on Battery
#!/bin/sh
#########################################################
# This shell script if placed in /etc/apcupsd #
# will be called by /etc/apcupsd/apccontrol when the UPS#
# goes on batteries. #
# We send an email message to root to notify him. #
#########################################################
mailfile="/var/ipfire/dma/mail.conf"
if [ -f $mailfile ]; then
FROM=`grep -a SENDER $mailfile | cut -f2 -d=`
TO=`grep -a RECIPIENT $mailfile | cut -f2 -d=`
else
exit
fi
MSG="$HOSTNAME UPS $1 Power Failure!!!";
#Ready to start
apcaccess status > /var/log/apcupsd.status
time=`grep -a TIMELEFT /var/log/apcupsd.status | cut -f2 -d:`
statusdate=`grep -a "END APC" /var/log/apcupsd.status | cut -f2,3,4 -d:`
battery=`grep -a BCHARGE /var/log/apcupsd.status | cut -f2 -d:`
load=`grep -a LOADPCT /var/log/apcupsd.status | cut -f2 -d:`
voltage=`grep -a LINEV /var/log/apcupsd.status | cut -f2 -d:`
timeonbattery=`grep -a TONBATT /var/log/apcupsd.status | cut -f2 -d:`
systemdate=`date "+%a, %e.%m.%Y %H:%M:%S"`
(
echo From: $FROM
echo To: $TO
echo Subject: "$MSG"
echo ""
echo $MSG
echo ""
echo "Time left: "$time
echo "Time on battery: "$timeonbattery
echo "Charge level: "$battery
echo "Load: "$load
echo "Voltage: "$voltage
echo "UPS report time: "$statusdate
echo ""
echo "Last UPS Events:"
echo ""
tail /var/log/apcupsd.events | tac
echo ""
echo "Full UPS Status follows:"
apcaccess status
)| sudo -u nobody /usr/sbin/sendmail -t -f $FROM
exit 0
offbattery used to signal when UPS no longer on battery (OFF Battery)
#!/bin/sh
#
# This shell script if placed in /etc/apcupsd
# will be called by /etc/apcupsd/apccontrol when the
# UPS goes back on to the mains after a power failure.
# We send an email message to root to notify him.
#
mailfile="/var/ipfire/dma/mail.conf"
if [ -f $mailfile ]; then
FROM=`grep -a SENDER $mailfile | cut -f2 -d=`
TO=`grep -a RECIPIENT $mailfile | cut -f2 -d=`
else
exit
fi
MSG="$HOSTNAME UPS $1 Power has returned"
#
(
echo From: $FROM
echo To: $TO
echo Subject: "$MSG"
echo ""
echo $MSG
echo ""
echo "Last UPS Events:"
echo ""
tail /var/log/apcupsd.events | tac
echo ""
echo "Full UPS Status follows:"
apcaccess status
)| sudo -u nobody /usr/sbin/sendmail -t -f $FROM
exit 0
commfailure - used when APCUPSD lost communication with UPS
#!/bin/sh
#
# This shell script if placed in /etc/apcupsd
# will be called by /etc/apcupsd/apccontrol when apcupsd
# loses contact with the UPS (i.e. the serial connection is not responding).
# We send an email message to root to notify him.
#
mailfile="/var/ipfire/dma/mail.conf"
if [ -f $mailfile ]; then
FROM=`grep -a SENDER $mailfile | cut -f2 -d=`
TO=`grep -a RECIPIENT $mailfile | cut -f2 -d=`
else
exit
fi
MSG="$HOSTNAME Communications with UPS $1 lost"
#
(
echo From: $FROM
echo To: $TO
echo Subject: "$MSG"
echo ""
echo $MSG
echo ""
echo "Last UPS Events:"
echo ""
tail /var/log/apcupsd.events | tac
echo ""
echo "Full UPS Status follows:"
apcaccess status
)| sudo -u nobody /usr/sbin/sendmail -t -f $FROM
exit 0
commok - used when APCUPSD restore communication with UPS
#!/bin/sh
#
# This shell script if placed in /etc/apcupsd
# will be called by /etc/apcupsd/apccontrol when apcupsd
# restores contact with the UPS (i.e. the serial connection is restored).
# We send an email message to root to notify him.
#
mailfile="/var/ipfire/dma/mail.conf"
if [ -f $mailfile ]; then
FROM=`grep -a SENDER $mailfile | cut -f2 -d=`
TO=`grep -a RECIPIENT $mailfile | cut -f2 -d=`
else
exit
fi
MSG="$HOSTNAME Communications with UPS $1 restored"
#
(
echo From: $FROM
echo To: $TO
echo Subject: "$MSG"
echo ""
echo $MSG
echo ""
echo "Last UPS Events:"
echo ""
tail /var/log/apcupsd.events | tac
echo ""
echo "Full UPS Status follows:"
apcaccess status
)| sudo -u nobody /usr/sbin/sendmail -t -f $FROM
exit 0
How message looks like
ipfire UPS Back-UPS_CS_500 battery needs changing NOW!!!
Battery Install Date: 2021-01-20
Battery Voltage: 13.5 Volts 12.0 Volts
Time left: 33.5 Minutes
Cummulated time on battery: 104 Seconds
Battery Charge level and Nominal Voltage: 75.0 Percent
Load: 8.0 Percent
Voltage: 230.0 Volts
UPS report time: 2022-07-24 17:38:08 +0300
Full UPS Status follows:
APC : 001,046,1130
DATE : 2022-07-24 17:37:38 +0300
HOSTNAME : ipfire
VERSION : 3.14.14 (31 May 2016) unknown
UPSNAME : Back-UPS_CS_500
CABLE : USB Cable
DRIVER : USB UPS Driver
UPSMODE : Stand Alone
STARTTIME: 2022-07-22 16:43:04 +0300
MODEL : Back-UPS CS 500
STATUS : ONLINE
LINEV : 230.0 Volts
LOADPCT : 8.0 Percent
BCHARGE : 75.0 Percent
TIMELEFT : 33.5 Minutes
MBATTCHG : 25 Percent
MINTIMEL : 20 Minutes
MAXTIME : 0 Seconds
OUTPUTV : 230.0 Volts
SENSE : High
DWAKE : 0 Seconds
DSHUTD : 0 Seconds
LOTRANS : 196.0 Volts
HITRANS : 256.0 Volts
RETPCT : 0.0 Percent
ITEMP : 29.2 C
ALARMDEL : No alarm
BATTV : 13.5 Volts
LINEFREQ : 50.0 Hz
LASTXFER : Low line voltage
NUMXFERS : 3
XONBATT : 2022-07-24 16:41:01 +0300
TONBATT : 0 Seconds
CUMONBATT: 104 Seconds
XOFFBATT : 2022-07-24 16:42:02 +0300
SELFTEST : NO
STESTI : None
STATFLAG : 0x05000008
MANDATE : 2005-10-09
SERIALNO : BB0541072054
BATTDATE : 2021-01-20
NOMOUTV : 230 Volts
NOMINV : 230 Volts
NOMBATTV : 12.0 Volts
NOMPOWER : 300 Watts
FIRMWARE : 808.q7.I USB FW:q7
END APC : 2022-07-24 17:38:08 +0300