[Nut-upsuser] Running script right before primary shuts down

Erik De Boeck deboeck.erik at gmail.com
Fri Jun 13 15:27:12 BST 2025


Dear all,

I would like to gracefully shut down my router (Unifi Dream Router (UDR))
after my secondary has shut off, and before my primary shuts off (or in any
case, before the UPS powers down). Unfortunately, the router doesn't seem
to support NUT, but I've written a bash script, with which I can shut it
down as user *nut*, running command *sudo -H -u nut bash -c 'bash
/var/lib/nut/NUT-scripts/shutdownrouter.sh'*). (I assume that if any script
is to be run, it would be run as user *nut*.)

But now I'm trying to figure out how to call it, and I'm not sure...

   - I assume in *upsmon.conf* there should be a line *NOTIFYFLAG FSD
    SYSLOG+WALL+EXEC*)
   But then I wondered whether *FSD* was maybe too late a flag?
   - Then I assume *upssched.conf* plays a role. This is the current setup:

   CMDSCRIPT /etc/nut/upssched-cmd.sh
   PIPEFN /etc/nut/upssched.pipe
   LOCKFN /etc/nut/upssched.lock
   AT ONBATT * START-TIMER shutdown_timer 1200
   AT ONLINE * CANCEL-TIMER shutdown_timer
   AT LOWBATT * EXECUTE immediate_shutdown
   AT COMMBAD * START-TIMER commbad_timer 1200
   AT COMMOK * CANCEL-TIMER commbad_timer
   AT NOCOMM * EXECUTE commbad_shutdown
   AT SHUTDOWN * EXECUTE powerdown

   - Then I assume *upssched-cmd.sh* plays a role. This is the current
   setup:
   #!/bin/sh

   case $1 in
       shutdown_timer)
           logger -t upssched-cmd "UPS running on battery for too long,
   initiating shutdown"
           /usr/sbin/upsmon -c fsd
           ;;

       immediate_shutdown)
           logger -t upssched-cmd "UPS on battery critical, forced shutdown"
           /usr/sbin/upsmon -c fsd
           ;;

       commbad_timer)
           logger -t upssched-cmd "UPS communication failure persists,
   initiating shutdown"
           /usr/sbin/upsmon -c fsd
           ;;

       commbad_shutdown)
           logger -t upssched-cmd "UPS communication failed, initiating
   shutdown"
           /usr/sbin/upsmon -c fsd
           ;;

       powerdown)
           logger -t upssched-cmd "Executing powerdown command"
           ;;

       *)
           logger -t upssched-cmd "Unrecognized command: $1"
           ;;
   esac

Where should I squeeze in */var/lib/nut/NUT-scripts/**shutdownrouter.*sh?

Thanks for anyone's help!

Kind regards,

Erik
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://alioth-lists.debian.net/pipermail/nut-upsuser/attachments/20250613/ccfb43f7/attachment.htm>


More information about the Nut-upsuser mailing list