Created
January 10, 2024 20:34
-
-
Save FlorianHeigl/47a33ac6c212928d7b021f328e3075f9 to your computer and use it in GitHub Desktop.
apcupsd
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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. | |
# | |
HOSTNAME=`hostname` | |
MSG="$HOSTNAME Communications with UPS $1 lost" | |
wait=12 | |
# Wait $wait seconds, and only send email | |
# if still not online | |
sleep $wait | |
status=$(/sbin/apcaccess status) | |
if echo "$status" | grep -q '^STATUS.*COMMLOST' ; then | |
logger -t apcupsd "commfailure for over $wait seconds. Sending mail" | |
( | |
echo "$MSG for over $wait seconds" | |
echo "$status" | |
) | $APCUPSD_MAIL -s "$MSG" $SYSADMIN | |
# ensure mail will also be sent on restore | |
rm -f /run/apcupsd.nomail | |
else | |
touch /run/apcupsd.nomail | |
logger -t apcupsd "commfailure for less than $wait seconds. Created nomail file, and not sending any email." | |
fi | |
exit 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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. | |
# | |
# wait at least as long as the wait defined in commfailure | |
# so that we know if we need to send mail or not | |
wait=13 | |
sleep $wait | |
if [ -f /run/apcupsd.nomail ]; then | |
logger -t apcupsd "Skip sending mail on restore (found nomail set by commfailure)" | |
exit | |
fi | |
HOSTNAME=`hostname` | |
MSG="$HOSTNAME Communications with UPS $1 restored" | |
# | |
( | |
echo "$MSG" | |
echo " " | |
/sbin/apcaccess status | |
) | $APCUPSD_MAIL -s "$MSG" $SYSADMIN | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
von https://serverfault.com/questions/444367/apcupsd-slave-client-keeps-loosing-and-restoring-communications-with-ups-master/976696#976696
muss noch mit shellcheck ueberarbeiten fuer qualitaet