#! /bin/sh
#
# This script should be called by upssched via the CMDSCRIPT directive.
#
# Here is a quick example to show how to handle a bunch of possible
# timer names with the help of the case structure.
#
# This script may be replaced with another program without harm
# (just be sure to avoid clashes with package-delivered files
# which might overwrite your custom changes).
#
# The first argument passed to your CMDSCRIPT is the name of the timer
# from your AT lines in upssched.conf.

# Feel free to remove or comment away these lines when you actually
# customize the script for your deployment:
echo "`date -u`: $0: THIS IS A SAMPLE SCRIPT, PLEASE TAILOR IT FOR YOUR DEPLOYMENT OF NUT!" >&2
logger -t upssched-cmd "THIS IS A SAMPLE SCRIPT, PLEASE TAILOR IT FOR YOUR DEPLOYMENT OF NUT!"

printf "`date -u`: UPSNAME='%s'\tNOTIFYTYPE='%s'\tNOTIFYMSG='%s'\targs=%s\n" "$UPSNAME" "$NOTIFYTYPE" "$NOTIFYMSG" "$*" >&2
printf "UPSNAME='%s' NOTIFYTYPE='%s' NOTIFYMSG='%s' args=%s\n" "$UPSNAME" "$NOTIFYTYPE" "$NOTIFYMSG" "$*" | logger -t upssched-cmd-received-NOTIFYTYPE

#set

# Handle received timer names, as defined in your upssched.conf (example):
case "$1" in
	onbattwarn)
		# Send a notification mail
		echo "The UPS has been on battery for awhile" \
		| mail -s"UPS monitor" bofh@pager.example.com
		# Create a flag-file on the filesystem, for your own processing
		/usr/bin/touch /some/path/ups-on-battery
		;;
	ups-back-on-power)
		# Delete the flag-file on the filesystem
		/bin/rm -f /some/path/ups-on-battery
		;;
	upsgone)
		logger -t upssched-cmd "The communication with UPS has been gone for awhile"
		;;
	*)
		logger -t upssched-cmd "Unrecognized command: $1"
		;;
esac

