#!/bin/sh ######################################## # Description: This script is used to handle the different events for the # apcupsd service. # Required files: apcupsd, sleep, shutdown, sh, echo, wall, hostname, date, # printf, msmtp # Last modified: May 22, 2016 ######################################## #################### # Set variables #################### prefix=/usr/local exec_prefix=/usr/local apcpid=/var/run/apcupsd.pid apcupsd=/usr/local/sbin/apcupsd sleep=/bin/sleep shutdown=/sbin/shutdown scriptshell=/bin/sh scriptdir=/usr/local/etc/apcupsd echo=/bin/echo wall=/usr/bin/wall hostname=/bin/hostname host=`$hostname -s` date=/bin/date current_day=`$date +%m/%d/%y` current_time=`$date +%H:%M:%S` timestamp="$current_day $current_time" printf=/usr/bin/printf from=testuser@gmail.com recipient=alerts@test.com msmtp=/usr/local/bin/msmtp msmtp_config=/usr/local/etc/msmtprc if [ -f $scriptdir/${1} -a -x $scriptdir/${1} ] then $scriptdir/${1} ${2} ${3} ${4} # exit code 99 means he does not want us to do default action if [ $? = 99 ] ; then exit 0 fi fi case "$1" in killpower) ;; commfailure) ;; commok) ;; powerout) ;; onbattery) ;; offbattery) ;; mainsback) ;; failing) ;; timeout) ;; loadlimit) ;; runlimit) ;; doreboot) ;; doshutdown) description="UPS ${2} initiated shutdown sequence in 15 seconds." $echo "[$timestamp] $description" | $wall $sleep 15 body="$description" subject="Network Alert: Apcupsd event (${1}) on $host [$timestamp]" $printf "From: $from\nTo: $recipient\nSubject: $subject\n\n$body" | $msmtp --file=$msmtp_config -t $shutdown -p now "apcupsd UPS ${2} initiated shutdown" ;; annoyme) ;; emergency) ;; changeme) ;; remotedown) description="Remote shutdown. Beginning shutdown sequence." $echo "[$timestamp] $description" | $wall $sleep 15 body="$description" subject="Network Alert: Apcupsd event (${1}) on $host [$timestamp]" $printf "From: $from\nTo: $recipient\nSubject: $subject\n\n$body" | $msmtp --file=$msmtp_config -t $shutdown -p now "apcupsd UPS ${2} initiated shutdown" startselftest) ;; endselftest) ;; battdetach) ;; battattach) ;; *) echo "Usage: ${0##*/} command" echo " warning: this script is intended to be launched by" echo " apcupsd and should never be launched by users." exit 1 ;; esac