<html>
<head>
<meta http-equiv="Content-Type" content="text/html;
charset=windows-1252">
</head>
<body smarttemplateinserted="true">
<div id="smartTemplate4-template"><font size="2" face="Verdana">Hi
Roger,<br>
<br>
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.<br>
<br>
</font><font size="2"><tt>#!/bin/bash</tt><tt><br>
</tt><tt>#</tt><tt><br>
</tt><tt># This script should be called by upssched via the
CMDSCRIPT directive.</tt><tt><br>
</tt><tt>#</tt><tt><br>
</tt><tt># Here is a quick example to show how to handle a bunch
of possible</tt><tt><br>
</tt><tt># timer names with the help of the case structure.</tt><tt><br>
</tt><tt>#</tt><tt><br>
</tt><tt># This script may be replaced with another program
without harm.</tt><tt><br>
</tt><tt>#</tt><tt><br>
</tt><tt># The first argument passed to your CMDSCRIPT is the
name of the timer</tt><tt><br>
</tt><tt># from your AT lines.</tt><tt><br>
</tt><tt>OPTION="$1"</tt><tt><br>
</tt><tt>SCRIPT="$0"</tt><tt><br>
</tt><tt><br>
</tt><tt>function MyLogging () {</tt><tt><br>
</tt><tt> echo "$1"</tt><tt><br>
</tt><tt> logger -t $SCRIPT $1</tt><tt><br>
</tt><tt>}</tt><tt><br>
</tt><tt><br>
</tt><tt>function Shutdown () {</tt><tt><br>
</tt><tt> MyLogging "NUT upssched \"lowbatt\" sequence start:
UPS Low Battery; Begin shutting down clients"</tt><tt><br>
</tt><tt> /etc/nut/scripts/shutdown-control &</tt><tt><br>
</tt><tt> MyLogging "NUT upssched \"lowbatt\" sequence
initiated"</tt><tt><br>
</tt><tt>}</tt><tt><br>
</tt><tt><br>
</tt><tt>MyLogging "Script called with arg $OPTION"</tt><tt><br>
</tt><tt><br>
</tt><tt>UPS_STATE=$(upsc myups1@localhost:3493 ups.status)</tt><tt><br>
</tt><tt>MyLogging "NUT upsmon UPS state: $UPS_STATE"</tt><tt><br>
</tt><tt><br>
</tt><tt>BAT_PERCENT=$(upsc myups1@localhost:3493
battery.charge)</tt><tt><br>
</tt><tt>MyLogging "NUT upsmon battery percent: $BAT_PERCENT"</tt><tt><br>
</tt><tt><br>
</tt><tt>case $OPTION in</tt><tt><br>
</tt><tt> lowbatt)</tt><tt><br>
</tt><tt> if [[ $UPS_STATE =~ "OL" ]]; then</tt><tt><br>
</tt><tt> SLEEP_TIME=6</tt><tt><br>
</tt><tt> MyLogging "NUT upsmon set \"lowbatt\" state
and \"online\" state together - Perform extra checks before
initiating shutdown"</tt><tt><br>
</tt><tt> MyLogging "Sleep $SLEEP_TIME seconds and
check UPS status again"</tt><tt><br>
</tt><tt> sleep $SLEEP_TIME</tt><tt><br>
</tt><tt> UPS_STATE_2=$(upsc myups1@localhost:3493
ups.status)</tt><tt><br>
</tt><tt> MyLogging "NUT upsmon UPS state:
$UPS_STATE_2"</tt><tt><br>
</tt><tt> if [[ $UPS_STATE_2 =~ "LB" ]]; then</tt><tt><br>
</tt><tt> Shutdown</tt><tt><br>
</tt><tt> else</tt><tt><br>
</tt><tt> MyLogging "\"LB\" not in UPS state
string after retry - Not performing shutdown"</tt><tt><br>
</tt><tt> fi</tt><tt><br>
</tt><tt> else</tt><tt><br>
</tt><tt> Shutdown</tt><tt><br>
</tt><tt> fi</tt><tt><br>
</tt><tt> ;;</tt><tt><br>
</tt><tt> onbatt)</tt><tt><br>
</tt><tt> MyLogging "UPS on battery"</tt><tt><br>
</tt><tt> ;;</tt><tt><br>
</tt><tt> online)</tt><tt><br>
</tt><tt> MyLogging "UPS power restored and back online"</tt><tt><br>
</tt><tt> ;;</tt><tt><br>
</tt><tt> upsgone)</tt><tt><br>
</tt><tt> MyLogging "The UPS has been gone for awhile"</tt><tt><br>
</tt><tt> ;;</tt><tt><br>
</tt><tt> *)</tt><tt><br>
</tt><tt> MyLogging "Unrecognized arg: $OPTION"</tt><tt><br>
</tt><tt> ;;</tt><tt><br>
</tt><tt>esac</tt><tt><br>
</tt><tt><br>
</tt><tt>exit 0</tt><tt><br>
</tt></font><font size="2" face="Verdana"><br>
Thanks again!<br>
-MikeD<br>
</font></div>
<br>
<div id="smartTemplate4-quoteHeader">
<hr>
<font size="2" face="Consolas">
<b>Date:</b> Sunday, May 26, 2019, at 02:26:31 AM PDT (GMT/UMT
-0700)<br>
<b>From:</b> Roger Price <a class="moz-txt-link-rfc2396E" href="mailto:roger@rogerprice.org"><roger@rogerprice.org></a><br>
<b>To:</b> Nut Users <a class="moz-txt-link-rfc2396E" href="mailto:nut-upsuser@alioth-lists.debian.net"><nut-upsuser@alioth-lists.debian.net></a><br>
<b>Subject:</b> Re: [Nut-upsuser] Low Battery False Alarms<br>
</font>
<br>
</div>
<div class="replaced-blockquote"
cite="mid:alpine.LSU.2.20.1905261117330.43054@titan" type="cite">On
Sat, 25 May 2019, Mike Dillinger wrote:
<br>
<br>
How about something like this:
<br>
<br>
<blockquote type="cite"> case $OPTION in
<br>
lowbatt)
<br>
</blockquote>
MSG="NUT upssched \"lowbatt\" confirmation begins.
Waiting for 5 seconds"
<br>
echo "$SCRIPT: $MSG"
<br>
logger -t $SCRIPT "$MSG"
<br>
Wait for 5 seconds
<br>
CHARGE=$( upsc <myups> battery.charge )
<br>
if CHARGE ok then exit from script
<br>
<blockquote type="cite"> MSG="NUT upssched
\"lowbatt\" sequence start: UPS Low Battery; Begin shutting down
clients"
<br>
echo "$SCRIPT: $MSG"
<br>
logger -t $SCRIPT "$MSG"
<br>
/etc/nut/scripts/shutdown-control &
<br>
MSG="NUT upssched \"lowbatt\" sequence initiated"
<br>
echo "$SCRIPT: $MSG"
<br>
logger -t $SCRIPT "$MSG"
<br>
;;
<br>
</blockquote>
...
<br>
<blockquote type="cite"> esac
<br>
exit 0<br>
</blockquote>
<br>
<fieldset class="mimeAttachmentHeader"></fieldset>
<pre class="moz-quote-pre" wrap="">_______________________________________________
Nut-upsuser mailing list
<a class="moz-txt-link-abbreviated" href="mailto:Nut-upsuser@alioth-lists.debian.net">Nut-upsuser@alioth-lists.debian.net</a>
<a class="moz-txt-link-freetext" href="https://alioth-lists.debian.net/cgi-bin/mailman/listinfo/nut-upsuser">https://alioth-lists.debian.net/cgi-bin/mailman/listinfo/nut-upsuser</a></pre>
</div>
<br>
</body>
</html>