5 rem This is the Windows apccontrol file.
\r
8 rem Assign parameters to named variables
\r
12 rem Strip leading and trailing quotation marks from paths.
\r
13 rem This is easily accomplished on NT, but Win95/98/ME
\r
14 rem require an evil little trick with 'FOR'.
\r
15 SET sbindir=%sbindir:"=%
\r
16 IF "%sbindir%" == "" FOR %%A IN (%5) DO SET sbindir=%%A
\r
18 rem Paths to important executables
\r
19 SET APCUPSD="%sbindir%\apcupsd"
\r
20 SET SHUTDOWN="%sbindir%\shutdown"
\r
21 SET BACKGROUND="%sbindir%\background"
\r
23 rem Only do popups on Win95/98/ME/NT. All other platforms support
\r
24 rem balloon notifications which are provided by apctray.
\r
26 VER | FIND /I "Windows 95" > NUL
\r
27 IF NOT ERRORLEVEL 1 SET POPUP=%BACKGROUND% "%sbindir%\popup"
\r
28 VER | FIND /I "Windows 98" > NUL
\r
29 IF NOT ERRORLEVEL 1 SET POPUP=%BACKGROUND% "%sbindir%\popup"
\r
30 VER | FIND /I "Windows ME" > NUL
\r
31 IF NOT ERRORLEVEL 1 SET POPUP=%BACKGROUND% "%sbindir%\popup"
\r
32 VER | FIND /I "Windows NT" > NUL
\r
33 IF NOT ERRORLEVEL 1 SET POPUP=%BACKGROUND% "%sbindir%\popup"
\r
36 rem This piece is to substitute the default behaviour with your own script,
\r
37 rem perl, C program, etc.
\r
39 rem You can customize any command by creating an executable file (may be a
\r
40 rem script or a compiled program) and naming it the same as the %1 parameter
\r
41 rem passed by apcupsd to this script. We will accept files with any extension
\r
42 rem included in PATHEXT (*.exe, *.bat, *.cmd, etc).
\r
44 rem After executing your script, apccontrol continues with the default action.
\r
45 rem If you do not want apccontrol to continue, exit your script with exit
\r
46 rem code 99. E.g. "exit /b 99".
\r
48 rem WARNING: please be aware that if you add any commands before the shutdown
\r
49 rem in the downshutdown) case and your command errors or stalls, it will
\r
50 rem prevent your machine from being shutdown, so test, test, test to
\r
51 rem make sure it works correctly.
\r
53 rem The apccontrol.bat file will be replaced every time apcupsd is installed,
\r
54 rem so do NOT make event modifications in this file. Instead, override the
\r
55 rem event actions using event scripts as described above.
\r
58 rem Use CALL here because event script might be a batch file itself
\r
59 CALL ".\%command%" 2> NUL
\r
61 rem This is retarded. "IF ERRORLEVEL 99" means greater-than-or-
\r
62 rem equal-to 99, so we have to synthesize an == using two IFs.
\r
63 rem Ahh, the glory of Windows batch programming. At least they
\r
64 rem gave us a NOT op.
\r
65 IF NOT ERRORLEVEL 99 GOTO :events
\r
66 IF NOT ERRORLEVEL 100 GOTO :done
\r
71 rem powerout, onbattery, offbattery, mainsback events occur
\r
75 IF "%command%" == "commfailure" GOTO :commfailure
\r
76 IF "%command%" == "commok" GOTO :commok
\r
77 IF "%command%" == "powerout" GOTO :powerout
\r
78 IF "%command%" == "onbattery" GOTO :onbattery
\r
79 IF "%command%" == "offbattery" GOTO :offbattery
\r
80 IF "%command%" == "mainsback" GOTO :mainsback
\r
81 IF "%command%" == "failing" GOTO :failing
\r
82 IF "%command%" == "timeout" GOTO :timeout
\r
83 IF "%command%" == "loadlimit" GOTO :loadlimit
\r
84 IF "%command%" == "runlimit" GOTO :runlimit
\r
85 IF "%command%" == "doshutdown" GOTO :doshutdown
\r
86 IF "%command%" == "annoyme" GOTO :annoyme
\r
87 IF "%command%" == "emergency" GOTO :emergency
\r
88 IF "%command%" == "changeme" GOTO :changeme
\r
89 IF "%command%" == "remotedown" GOTO :remotedown
\r
90 IF "%command%" == "startselftest" GOTO :startselftest
\r
91 IF "%command%" == "endselftest" GOTO :endselftest
\r
92 IF "%command%" == "battdetach" GOTO :battdetach
\r
93 IF "%command%" == "battattach" GOTO :battattach
\r
95 echo Unknown command '%command%'
\r
97 echo Usage: %0 command
\r
99 echo Warning: this script is intended to be launched by
\r
100 echo apcupsd and should never be launched by users.
\r
104 %POPUP% "Communications with UPS lost."
\r
108 %POPUP% "Communciations with UPS restored."
\r
115 %POPUP% "Power failure. Running on UPS batteries."
\r
119 %POPUP% "Power has returned. No longer running on UPS batteries."
\r
126 %POPUP% "UPS battery power exhaused. Doing shutdown."
\r
130 %POPUP% "UPS battery runtime limit exceeded. Doing shutdown."
\r
134 %POPUP% "UPS battery discharge limit reached. Doing shutdown."
\r
138 %POPUP% "UPS battery runtime percent reached. Doing shutdown."
\r
143 rem If you want to try to power down your UPS, uncomment
\r
144 rem out the following lines, but be warned that if the
\r
145 rem following shutdown -h now doesn't work, you may find
\r
146 rem the power being shut off to a running computer :-(
\r
147 rem Also note, we do this in the doshutdown case, because
\r
148 rem there is no way to get control when the machine is
\r
149 rem shutdown to call this script with --killpower. As
\r
150 rem a consequence, we do both killpower and shutdown
\r
152 rem Note that Win32 lacks a portable way to delay for a
\r
153 rem given time, so we use the trick of pinging a
\r
154 rem non-existent IP address with a given timeout.
\r
156 rem %APCUPSD% /kill
\r
157 rem ping -n 1 -w 5000 10.255.255.254 > NUL
\r
158 rem %POPUP% "Doing %APCUPSD% --killpower"
\r
159 rem %APCUPSD% --killpower
\r
160 rem ping -n 1 -w 12000 10.255.255.254 > NUL
\r
166 %POPUP% "Power problems: please logoff."
\r
170 %POPUP% "Emergency shutdown initiated."
\r
174 %POPUP% "Emergency! UPS batteries have failed: Change them NOW"
\r
178 %POPUP% "Shutdown due to master state or comms lost."
\r
182 %POPUP% "Self-test starting"
\r
186 %POPUP% "Self-test completed"
\r
190 %POPUP% "Battery disconnected"
\r
194 %POPUP% "Battery reattached"
\r
198 rem That's all, folks
\r