#!/bin/bash

# early-shutdown
#
# Jason Healy
#
# This script parses output from upssched and shuts the machine down early
# (that is, before the UPS battery goes critical).
#
# It's just a case statement, so it would be relatively easy to add support
# for other events as well (just create new arguments to recognize, and
# add them to upssched.conf).
#

case "${1}" in

  early-shutdown)
    logger -p daemon.alert -t early-shutdown "Early Shutdown time has arrived!"
    /usr/local/nut_upsmon/sbin/upsmon -c fsd
  ;;

  forced-shutdown)
    logger -p daemon.alert -t early-shutdown "UPS Master sent Forced Shutdown Request"
    /usr/local/nut_upsmon/sbin/upsmon -c fsd
  ;;

  *)
    logger -p daemon.warning -t early-shutdown "Unknown command: ${1}"
  ;;

esac

