View difference between Paste ID: XpSsLGxQ and SmJ9q2S7
SHOW: | | - or go back to the newest paste.
1
:: Purpose:         DHCP server Watchdog & Failover script. Read notes below
2
:: Requirements:    1. Domain administrator credentials & "Logon as a batch job" rights
3
::                  2. Proper firewall configuration to allow connection
4
::                  3. Proper permissions on the DHCP backup directory
5
:: Author:          vocatus on reddit.com/r/usefulscripts
6-
:: Version:         1.2b + Added comment block explaining syntax rules for variables
6+
:: Version:         1.2c * Reworked CUR_DATE variable to handle more than one Date/Time format
7
::                         Can now handle ISO standard dates (yyyy-mm-dd) and Windows default dates (e.g. "Fri 01/24/2014")
8
::                  1.2b + Added comment block explaining syntax rules for variables
9
::                  1.2  + Added functionality to recover the DHCP database BACK to the primary server after a failure. Now when the backup server detects that
10
::                         the primary server has come back online after an outage, it will export its current copy of the DHCP database, upload it back to the 
11
::                         primary server, import it, and spin it back up using the most recent copy. This addresses the issue of new leases being passed out during
12
::                         an outage of the primary server and it not being aware of those leases when it comes back online.
13
::                       + Added "REMOTE_OPERATIING_PATH" variable that lets us specify where the remote server keeps its DHCP working files during operation
14
::                       + Added "UPDATED" variable to note when the script was last updated
15
::                  1.1c + Added quotes around all variables that could contain paths
16
::                       + Added full path to SC.exe to prevent failure in the event %PATH% gets corrupted or mangled (this happened in testing)
17
::                       * Fixed a glitch that could occur when pinging an assumed-down primary server that would incorrectly think it was back up
18
::                       - Removed almost every entry of "2>&1" since it's really not needed
19
::                  1.1b - Changed DATE to CUR_DATE format to be consistent with all other scripts
20
::                  1.1  - Comments improvement
21
::                       / Tuned some parameters (ping count on checking)
22
::                       / Some logging tweaks
23
::                       / Renamed FAILOVER_DELAY to FAILOVER_RECHECK_DELAY for clarity
24
::                  1.0d * Some logging tweaks
25
::                  1.0c * Some logging tweaks
26
::                  1.0 Initial write
27
:: Notes:           I wrote this script after failing to find a satisfactory method of performing
28
::                  watchdog/failover between two Windows Server 2008 R2 DHCP servers.
29
::                 
30
:: Use:             This script has two modes: "Watchdog" and "Failover." 
31
::                  - Watchdog checks the status of the remote DHCP service, logs it, and then grabs the remote DHCP db backup file and imports it.
32
::                  - Failover mode is activated when the script cannot determine the status of the remote DHCP server. The script then activates 
33-
:: Instructions: 
33+
34-
::                  1. Tune the variables in this script to your desired backup location and frequency
34+
35
:: Instructions:    1. Tune the variables in this script to your desired backup location and frequency
36
::                  2. On the primary server: set the DHCP backup interval to your desired backup frequency. The value is in minutes; I recommend 5 minutes.
37
::                     You do this by modifying this registry key: HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\DHCPServer\Parameters\BackupInterval
38
::                  3. On the backup server:  set this script to run as a scheduled task. I recommend every 10 minutes. 
39
:: Notice: 
40
::                 !! Make sure to set it only to run if it isn't already running! If there is a failover you could have 
41
::                    Task Scheduler spawn a new instance of the script every n minutes and end up with hundreds of copies
42
::                    of this script running.
43
44-
:: Prep
44+
45
::::::::::
46
:: Prep :: -- Don't change anything in this section
47
::::::::::
48-
set VERSION=1.2b
48+
49-
set UPDATED=2013-09-16
49+
50
cls
51
set VERSION=1.2c
52
set UPDATED=2014-01-27
53
if "%DATE:~-5,1%"=="/" (set CUR_DATE=%DATE:~-4%-%DATE:~4,2%-%DATE:~7,2%) else (set CUR_DATE=%DATE%)
54-
:: VARIABLES :: - Set these
54+
55
56
57
:::::::::::::::
58
:: VARIABLES :: -- Set these to your desired values
59
:::::::::::::::
60
:: Rules for variables:
61
::  * NO quotes!                       (bad:  "c:\directory\path"       )
62
::  * NO trailing slashes on the path! (bad:   c:\directory\            )
63
::  * Spaces are okay                  (okay:  c:\my folder\with spaces )
64-
set REMOTE_SERVER=mikado
64+
65
::                                     (       \\172.16.1.5\share name  )
66
:: Remote server is the PRIMARY DHCP server we're watching. Use a hostname or IP address.
67
set REMOTE_SERVER=someserver
68
69
:: Location of the automatic DHCP backup file on the primary server. Windows generates this automatically.
70
:: Best practice is to leave this alone, unless you have a custom backup location.
71
:: The script builds the backup line like this: \\%REMOTE_SERVER%\c$\%REMOTE_BACKUP_PATH%
72
set REMOTE_BACKUP_PATH=Windows\system32\dhcp\backup
73
74
:: Location of the operational DHCP database files on the remote (primary) server.
75
:: Best practice is to leave this alone, unless you have a custom location. Changing this will break the 
76
:: function that re-uploads the most current db back to the primary server after a failure. This doesn't 
77
:: ruin the script, but if the backup server passed out any IP's while the primary server was down, the 
78
:: primary server won't know about them when it comes back up.
79
set REMOTE_OPERATING_PATH=Windows\system32\dhcp
80
81
:: Location of your backup/standby file. I normally copy directly to my backup server's DHCP directory. 
82
:: The script builds the local backup line like this: c:\windows\system32\dhcp\[backup folders]
83
set LOCAL_BACKUP_PATH=%SystemRoot%\system32\dhcp
84
85
:: When a failover is triggered, how many seconds should we wait in between each attempt to contact the primary server again?
86
set FAILOVER_RECHECK_DELAY=15
87
88
:: Log options. Don't put an extension on the log file name. (Important!) The script sets this later on.
89
set LOGPATH=%SystemDrive%\Logs
90
set LOGFILE=%COMPUTERNAME%_DHCP_watchdog
91
92
:: Max log file size allowed (in bytes) before rotation and archive. I recommend setting this to 2 MB (2097152).
93-
:: \/ Don't touch anything below this line. If you do, you will break something.
93+
94-
set CUR_DATE=%DATE:~-4%-%DATE:~4,2%-%DATE:~7,2%
94+
95
96
97
:::::::::::::::::::::::
98
:: LOG FILE HANDLING :: - This section handles the log file
99
:::::::::::::::::::::::
100
:: Make the logfile if it doesn't exist
101
if not exist %LOGPATH% mkdir %LOGPATH%
102
if not exist %LOGPATH%\%LOGFILE%.log goto new_log
103
104
:: Check log size. If it hasn't exceeded our size limit, jump straight to Watchdog mode
105
for %%R in (%LOGPATH%\%LOGFILE%.log) do if %%~zR LSS %LOG_MAX_SIZE% goto newrun
106
107
:: However, if the log was too big, go ahead and rotate it.
108
pushd %LOGPATH%
109
del %LOGFILE%.ancient 2>NUL
110
rename %LOGFILE%.oldest %LOGFILE%.ancient 2>NUL
111
rename %LOGFILE%.older %LOGFILE%.oldest 2>NUL
112
rename %LOGFILE%.old %LOGFILE%.older 2>NUL
113
rename %LOGFILE%.log %LOGFILE%.old 2>NUL
114
popd
115
116
:: And then create the header for the new log file
117
:new_log
118
echo ------------------------------------------------------------------------------------->> %LOGPATH%\%LOGFILE%.log
119
echo  Initializing new DHCP Server Watchdog log on %CUR_DATE% at %TIME%, max log size %LOG_MAX_SIZE% bytes>> %LOGPATH%\%LOGFILE%.log
120
echo ------------------------------------------------------------------------------------->> %LOGPATH%\%LOGFILE%.log
121
echo.>> %LOGPATH%\%LOGFILE%.log
122
123
:: New run section - if we just launched the script, write a header for this run
124
:newrun
125
echo ------------------------------------------------------------------------------------->> %LOGPATH%\%LOGFILE%.log
126
echo  DHCP Server Watchdog v%VERSION%, %CUR_DATE%>> %LOGPATH%\%LOGFILE%.log
127
echo   Running as %USERDOMAIN%\%USERNAME% on %COMPUTERNAME%>> %LOGPATH%\%LOGFILE%.log
128
echo.>> %LOGPATH%\%LOGFILE%.log
129
echo  Job Options>> %LOGPATH%\%LOGFILE%.log
130
echo   Log location:            %LOGPATH%\%LOGFILE%.log>> %LOGPATH%\%LOGFILE%.log
131
echo   Log max size:            %LOG_MAX_SIZE% bytes>> %LOGPATH%\%LOGFILE%.log
132
echo   Watching primary server: %REMOTE_SERVER%>> %LOGPATH%\%LOGFILE%.log
133
echo   Mirroring this DHCP db:  %REMOTE_BACKUP_PATH%>> %LOGPATH%\%LOGFILE%.log
134
echo   Local backup location:   %LOCAL_BACKUP_PATH%>> %LOGPATH%\%LOGFILE%.log
135
echo ------------------------------------------------------------------------------------->> %LOGPATH%\%LOGFILE%.log
136
echo %CUR_DATE% %TIME%         Starting Watchdog mode.>> %LOGPATH%\%LOGFILE%.log
137
echo.
138
echo  DHCP Server Watchdog v%VERSION%
139
echo   Running as: %USERDOMAIN%\%USERNAME% on %COMPUTERNAME%
140
echo   Log:        %LOGPATH%\%LOGFILE%.log
141
142
143
:::::::::::::::::::
144
:: WATCHDOG MODE ::
145
:::::::::::::::::::
146
:watchdog
147
148
:: Ping the server to see if it's up
149
echo.
150
echo   Verifying proper operation of DHCP server on %REMOTE_SERVER%, please wait...
151
echo.
152
echo %CUR_DATE% %TIME%         Pinging %REMOTE_SERVER%...>> %LOGPATH%\%LOGFILE%.log
153
echo %CUR_DATE% %TIME%         Pinging %REMOTE_SERVER%...
154
ping %REMOTE_SERVER% -n %FAILOVER_RECHECK_DELAY% >NUL
155
if %ERRORLEVEL%==1 echo %CUR_DATE% %TIME% WARNING %REMOTE_SERVER% failed to respond to ping. && echo %CUR_DATE% %TIME% WARNING %REMOTE_SERVER% failed to respond to ping.>> %LOGPATH%\%LOGFILE%.log
156
if not %ERRORLEVEL%==1 echo %CUR_DATE% %TIME% SUCCESS %REMOTE_SERVER% responded to ping. && echo %CUR_DATE% %TIME% SUCCESS %REMOTE_SERVER% responded to ping.>> %LOGPATH%\%LOGFILE%.log
157
158
:: Check & Log
159
echo %CUR_DATE% %TIME%         Checking DHCP server status on %REMOTE_SERVER%...>> %LOGPATH%\%LOGFILE%.log
160
echo %CUR_DATE% %TIME%         Checking DHCP server status on %REMOTE_SERVER%...
161
162
:: Reset ERRORLEVEL back to 0
163
ver > NUL
164
165
:: Use "SC" to check the status of "Dhcpserver" service, find the "RUNNING" state, and act accordingly based on the return code
166
%WINDIR%\System32\sc.exe \\%REMOTE_SERVER% query Dhcpserver | find "RUNNING" >NUL
167
if %ERRORLEVEL%==0 echo %CUR_DATE% %TIME% SUCCESS The DHCP service is running on %REMOTE_SERVER%.>> %LOGPATH%\%LOGFILE%.log
168
if %ERRORLEVEL%==0 echo %CUR_DATE% %TIME% SUCCESS The DHCP service is running on %REMOTE_SERVER%.
169
170
:: This section only executes if the test failed.
171
if not %ERRORLEVEL%==0 ( 
172
	echo %CUR_DATE% %TIME% FAILURE The DHCP service is not running on %REMOTE_SERVER%.>> %LOGPATH%\%LOGFILE%.log
173
	echo %CUR_DATE% %TIME%         Activating failover procedure. Local DHCP server will be initialized using most recent successful backup.>> %LOGPATH%\%LOGFILE%.log
174
	echo %CUR_DATE% %TIME% FAILURE The DHCP service is not running on %REMOTE_SERVER%.
175
	echo %CUR_DATE% %TIME%         Activating failover procedure. Local DHCP server will be initialized using most recent successful backup.
176
	goto failover
177
	)
178
179
:: Reset ERRORLEVEL back to 0
180
ver > NUL
181
182
:: Fetch
183
echo %CUR_DATE% %TIME%         Fetching DHCP database backup from %REMOTE_SERVER%...>> %LOGPATH%\%LOGFILE%.log
184
echo %CUR_DATE% %TIME%         Fetching DHCP database backup from %REMOTE_SERVER%...
185
xcopy "\\%REMOTE_SERVER%\c$\%REMOTE_BACKUP_PATH%\*" "%LOCAL_BACKUP_PATH%\backup_new_pending\" /E /Y /Q >NUL
186
187
:: If the copy SUCCEEDED, this executes
188
if %ERRORLEVEL%==0 ( 
189
	echo %CUR_DATE% %TIME% SUCCESS Backup fetched from %REMOTE_SERVER%.>> %LOGPATH%\%LOGFILE%.log
190
	echo %CUR_DATE% %TIME% SUCCESS Backup fetched from %REMOTE_SERVER%.
191
	echo %CUR_DATE% %TIME%         Rotating database backups...>> %LOGPATH%\%LOGFILE%.log
192
	echo %CUR_DATE% %TIME%         Rotating database backups...
193
	:: Rotate backups and use newest copy
194
	rmdir /S /Q %LOCAL_BACKUP_PATH%\backup5
195
	if exist "%LOCAL_BACKUP_PATH%\backup4" move /Y "%LOCAL_BACKUP_PATH%\backup4" "%LOCAL_BACKUP_PATH%\backup5"
196
	if exist "%LOCAL_BACKUP_PATH%\backup3" move /Y "%LOCAL_BACKUP_PATH%\backup3" "%LOCAL_BACKUP_PATH%\backup4"
197
	if exist "%LOCAL_BACKUP_PATH%\backup2" move /Y "%LOCAL_BACKUP_PATH%\backup2" "%LOCAL_BACKUP_PATH%\backup3"
198
	if exist "%LOCAL_BACKUP_PATH%\backup" move /Y "%LOCAL_BACKUP_PATH%\backup" "%LOCAL_BACKUP_PATH%\backup2"
199
	move /Y "%LOCAL_BACKUP_PATH%\backup_new_pending" "%LOCAL_BACKUP_PATH%\backup" >NUL
200
	echo %CUR_DATE% %TIME%         Database backups rotated.>> %LOGPATH%\%LOGFILE%.log
201
	echo %CUR_DATE% %TIME%         Database backups rotated.
202
	)
203
204
:: If the copy FAILED, this executes:
205
if not %ERRORLEVEL%==0 ( 
206
	echo %CUR_DATE% %TIME% WARNING There was an error copying the backup from %REMOTE_SERVER%.>> %LOGPATH%\%LOGFILE%.log
207
	echo %CUR_DATE% %TIME%         You may want to look into this since we were able to check the DHCPserver service status but the file copy failed.>> %LOGPATH%\%LOGFILE%.log
208
	echo %CUR_DATE% %TIME%         Skipping new database import due to copy failure.>> %LOGPATH%\%LOGFILE%.log
209
	echo %CUR_DATE% %TIME%         Job complete with errors.>> %LOGPATH%\%LOGFILE%.log
210
	echo %CUR_DATE% %TIME% WARNING There was an error copying the backup from %REMOTE_SERVER%.
211
	echo %CUR_DATE% %TIME%         You may want to look into this since we were able to check the DHCPserver service status but the file copy failed.
212
	echo %CUR_DATE% %TIME%         Skipping new database import due to copy failure.
213
	echo %CUR_DATE% %TIME%         Job complete with errors.
214
	)
215
	
216
:: Import database
217
echo %CUR_DATE% %TIME%         Starting local DHCP server to import new database...>> %LOGPATH%\%LOGFILE%.log
218
echo %CUR_DATE% %TIME%         Starting local DHCP server to import new database...
219
	net start Dhcpserver
220
echo %CUR_DATE% %TIME%         Local DHCP server running. Performing import...>> %LOGPATH%\%LOGFILE%.log
221
echo %CUR_DATE% %TIME%         Local DHCP server running. Performing import...
222
	netsh dhcp server restore "%LOCAL_BACKUP_PATH%\backup"
223
echo %CUR_DATE% %TIME%         Import complete.>> %LOGPATH%\%LOGFILE%.log
224
echo %CUR_DATE% %TIME%         Import complete.
225
echo %CUR_DATE% %TIME%         Stopping local DHCP server...>> %LOGPATH%\%LOGFILE%.log
226
echo %CUR_DATE% %TIME%         Stopping local DHCP server...
227
	sc stop Dhcpserver
228
echo %CUR_DATE% %TIME%         Local DHCP server stopped.>> %LOGPATH%\%LOGFILE%.log
229
echo %CUR_DATE% %TIME%         Local DHCP server stopped.
230
echo %CUR_DATE% %TIME% SUCCESS Job complete, DHCP database backed up and ready for use. Exiting.>> %LOGPATH%\%LOGFILE%.log
231
echo %CUR_DATE% %TIME% SUCCESS Job complete, DHCP database backed up and ready for use. Exiting.
232
goto EOF
233
234
235
:::::::::::::::::::
236
:: FAILOVER MODE ::
237
:::::::::::::::::::
238
239
:failover
240
:: Log this AND display to console
241
echo %CUR_DATE% %TIME% WARNING Failover activated.>> %LOGPATH%\%LOGFILE%.log
242
echo %CUR_DATE% %TIME%         Starting local DHCP server using most recent successful backup...>> %LOGPATH%\%LOGFILE%.log
243
echo.
244
echo %CUR_DATE% %TIME% WARNING Could not contact primary DHCP server %REMOTE_SERVER%. Failover activated.
245
echo %CUR_DATE% %TIME%         Starting local DHCP server using most recent successful backup...
246
echo.
247
	net start Dhcpserver
248
echo %CUR_DATE% %TIME%         Local DHCP server started.>> %LOGPATH%\%LOGFILE%.log
249
echo %CUR_DATE% %TIME%         Entering monitoring loop. Checking if %REMOTE_SERVER% is back up every %FAILOVER_RECHECK_DELAY% seconds...>> %LOGPATH%\%LOGFILE%.log
250
echo %CUR_DATE% %TIME%         Local DHCP server started.
251
echo %CUR_DATE% %TIME%         Entering monitoring loop. Checking if %REMOTE_SERVER% is back up every %FAILOVER_RECHECK_DELAY% seconds...
252
253
254
:failover_loop
255
:: First we ping the server
256
ping %REMOTE_SERVER% -n 5 >NUL
257
:: If no ping response, this section executes
258
IF NOT %ERRORLEVEL%==0 (
259
	echo %CUR_DATE% %TIME% FAILURE No ping response from %REMOTE_SERVER%. Waiting %FAILOVER_RECHECK_DELAY% seconds to check again.>> %LOGPATH%\%LOGFILE%.log
260
	echo %CUR_DATE% %TIME% FAILURE No ping response from %REMOTE_SERVER%. Waiting %FAILOVER_RECHECK_DELAY% seconds to check again.
261
	ping localhost -n %FAILOVER_RECHECK_DELAY% >NUL
262
	goto failover_loop
263
	)
264
265
:: If yes ping response, this section executes
266
:: This declaration is required to get the nested IF ERRORLEVEL test to function correctly
267
SETLOCAL ENABLEDELAYEDEXPANSION
268
if not %ERRORLEVEL%==1 (
269
	echo %CUR_DATE% %TIME% NOTICE  %REMOTE_SERVER% is responding to pings.>> %LOGPATH%\%LOGFILE%.log
270
	echo %CUR_DATE% %TIME% NOTICE  %REMOTE_SERVER% is responding to pings.
271
	echo %CUR_DATE% %TIME%         Checking DHCP server status on %REMOTE_SERVER%...>> %LOGPATH%\%LOGFILE%.log
272
	echo %CUR_DATE% %TIME%         Checking DHCP server status on %REMOTE_SERVER%...
273
	
274
	:: This section checks to see if the Dhcpserver service is back up and acts accordingly
275
	%WINDIR%\System32\sc.exe \\%REMOTE_SERVER% query Dhcpserver | find "RUNNING" >NUL
276
		:: The exclamation points around ERRORLEVEL here prevent it from incorrectly being expanded using the external ERRORLEVEL results from the first IF statement
277
		if !ERRORLEVEL!==0 (
278
				echo %CUR_DATE% %TIME% SUCCESS The DHCP service is running on %REMOTE_SERVER%.>> %LOGPATH%\%LOGFILE%.log
279
				echo %CUR_DATE% %TIME% SUCCESS The DHCP service is running on %REMOTE_SERVER%.
280
				echo %CUR_DATE% %TIME%         Primary DHCP server %REMOTE_SERVER% is back up. Beginning recovery procedures...>> %LOGPATH%\%LOGFILE%.log
281
				echo %CUR_DATE% %TIME%         Primary DHCP server %REMOTE_SERVER% is back up. Beginning recovery procedures...
282
				
283
				:: Back up the database that we've been running temporarily while the primary server was down
284
				echo %CUR_DATE% %TIME%         Exporting the current DHCP database...>> %LOGPATH%\%LOGFILE%.log
285
				echo %CUR_DATE% %TIME%         Exporting the current DHCP database...
286
				netsh dhcp server backup %TEMP%\DHCP-RECOVERY
287
				
288
				:: Stop our local server since we're done performing DHCP server duties
289
				echo %CUR_DATE% %TIME%         Stopping local DHCP server...>> %LOGPATH%\%LOGFILE%.log
290
				echo %CUR_DATE% %TIME%         Stopping local DHCP server...
291
				sc stop Dhcpserver
292
				
293
				:: Send the database back to the primary server
294
				echo %CUR_DATE% %TIME%         Uploading current DHCP database to %REMOTE_SERVER%...>> %LOGPATH%\%LOGFILE%.log
295
				echo %CUR_DATE% %TIME%         Uploading current DHCP database to %REMOTE_SERVER%...
296
				xcopy "%TEMP%\DHCP-RECOVERY\*" "\\%REMOTE_SERVER%\c$\%REMOTE_OPERATING_PATH%\DHCP-RECOVERY\" /S /Y /Q 2>NUL
297
298
				:: Import the current database on the primary server
299
				echo %CUR_DATE% %TIME%         Importing current DHCP database on %REMOTE_SERVER%...>> %LOGPATH%\%LOGFILE%.log
300
				echo %CUR_DATE% %TIME%         Importing current DHCP database on %REMOTE_SERVER%...
301
				netsh dhcp server \\%REMOTE_SERVER% restore "\\%REMOTE_SERVER%\c$\%REMOTE_OPERATING_PATH%\DHCP-RECOVERY"
302
				:: force a delay to let it stop
303
				ping -n 4 localhost >NUL
304
				
305
				:: Spin the primary server back up. For some reason we have to run the command twice for it to actually start. Don't ask.
306
				echo %CUR_DATE% %TIME%         Restarting DHCP server on %REMOTE_SERVER%...>> %LOGPATH%\%LOGFILE%.log
307
				echo %CUR_DATE% %TIME%         Restarting DHCP server on %REMOTE_SERVER%...
308
				sc \\%REMOTE_SERVER% stop Dhcpserver
309
				ping localhost -n 8 >NUL
310
				sc \\%REMOTE_SERVER% start Dhcpserver
311
				ping localhost -n 5 >NUL
312
				sc \\%REMOTE_SERVER% query Dhcpserver
313
				ping localhost -n 8 >NUL
314
				sc \\%REMOTE_SERVER% start Dhcpserver
315
				
316
				REM :: Check to make sure it's working
317
				REM echo %CUR_DATE% %TIME%         Verifying functionality on primary server...>> %LOGPATH%\%LOGFILE%.log
318
				REM echo %CUR_DATE% %TIME%         Verifying functionality on primary server...
319
				REM sc \\%REMOTE_SERVER% query Dhcpserver | find "RUNNING"
320
				REM if not %ERRORLEVEL%==0 echo %CUR_DATE% %TIME% FAILURE DHCP server on %REMOTE_SERVER% is not running. You should investigate this manually.>> %LOGPATH%\%LOGFILE%.log
321
				REM if %ERRORLEVEL%==0 echo %CUR_DATE% %TIME% SUCCESS DHCP server on %REMOTE_SERVER% is up and running. Recovery complete.>> %LOGPATH%\%LOGFILE%.log
322
323
				:: Clean up
324
				rmdir /S /Q %TEMP%\DHCP-RECOVERY
325
				
326
				:: Done.
327
				echo %CUR_DATE% %TIME%         Exiting.>> %LOGPATH%\%LOGFILE%.log
328
				echo %CUR_DATE% %TIME%         Exiting.
329
				goto EOF
330
				)
331
	)
332
ENDLOCAL
333
334
:: If the host responds to pings but the DHCP service isn't running, this executes
335
echo %CUR_DATE% %TIME% FAILURE %REMOTE_SERVER% is responding to pings, but DHCP isn't responding (yet?). Will try again in %FAILOVER_RECHECK_DELAY% seconds.>> %LOGPATH%\%LOGFILE%.log
336
echo %CUR_DATE% %TIME% FAILURE %REMOTE_SERVER% is responding to pings, but DHCP isn't responding (yet?). Will try again in %FAILOVER_RECHECK_DELAY% seconds.
337
ver >NUL
338
goto failover_loop
339
340
ENDLOCAL
341
echo.>> %LOGPATH%\%LOGFILE%.log
342
:EOF