Guest User

[BATCH] DHCP Failover/Watchdog v1.2

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