|
Hi
Roger,
Your previous reply got me thinking in this direction too, although I came up with a slightly different approach. Thanks for the help and suggestion. Below is what I came up with. #!/bin/bash # # 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. # # The first argument passed to your CMDSCRIPT is the name of the timer # from your AT lines. OPTION="$1" SCRIPT="$0" function MyLogging () { echo "$1" logger -t $SCRIPT $1 } function Shutdown () { MyLogging "NUT upssched \"lowbatt\" sequence start: UPS Low Battery; Begin shutting down clients" /etc/nut/scripts/shutdown-control & MyLogging "NUT upssched \"lowbatt\" sequence initiated" } MyLogging "Script called with arg $OPTION" UPS_STATE=$(upsc myups1@localhost:3493 ups.status) MyLogging "NUT upsmon UPS state: $UPS_STATE" BAT_PERCENT=$(upsc myups1@localhost:3493 battery.charge) MyLogging "NUT upsmon battery percent: $BAT_PERCENT" case $OPTION in lowbatt) if [[ $UPS_STATE =~ "OL" ]]; then SLEEP_TIME=6 MyLogging "NUT upsmon set \"lowbatt\" state and \"online\" state together - Perform extra checks before initiating shutdown" MyLogging "Sleep $SLEEP_TIME seconds and check UPS status again" sleep $SLEEP_TIME UPS_STATE_2=$(upsc myups1@localhost:3493 ups.status) MyLogging "NUT upsmon UPS state: $UPS_STATE_2" if [[ $UPS_STATE_2 =~ "LB" ]]; then Shutdown else MyLogging "\"LB\" not in UPS state string after retry - Not performing shutdown" fi else Shutdown fi ;; onbatt) MyLogging "UPS on battery" ;; online) MyLogging "UPS power restored and back online" ;; upsgone) MyLogging "The UPS has been gone for awhile" ;; *) MyLogging "Unrecognized arg: $OPTION" ;; esac exit 0 Thanks again! -MikeD Date: Sunday, May 26, 2019, at 02:26:31 AM PDT (GMT/UMT -0700) From: Roger Price <[email protected]> To: Nut Users <[email protected]> Subject: Re: [Nut-upsuser] Low Battery False Alarms On
Sat, 25 May 2019, Mike Dillinger wrote:
How about something like this: case $OPTION inMSG="NUT upssched \"lowbatt\" confirmation begins. Waiting for 5 seconds" echo "$SCRIPT: $MSG" logger -t $SCRIPT "$MSG" Wait for 5 seconds CHARGE=$( upsc <myups> battery.charge ) if CHARGE ok then exit from script MSG="NUT upssched \"lowbatt\" sequence start: UPS Low Battery; Begin shutting down clients"... esac _______________________________________________ Nut-upsuser mailing list [email protected] https://alioth-lists.debian.net/cgi-bin/mailman/listinfo/nut-upsuser |
_______________________________________________ Nut-upsuser mailing list [email protected] https://alioth-lists.debian.net/cgi-bin/mailman/listinfo/nut-upsuser
