Quantcast
Channel: The Official Scripting Guys Forum! forum
Viewing all articles
Browse latest Browse all 15028

Script to reboot remote servers in sequential order

$
0
0

I need a script to reboot remote servers in sequential order.

When the first server is rebooted, I want the script to wait for the server to come back online (sleep for like 5 - 10 minutes), check a critical windows service like netlogon service and make sure it's running before rebooting the next server. I want to do this for about 20 servers.

I have put up the below script but I am stuck in calling the loop command instead if using the server names etc...

Please help. Your help would be greatly appreciated.

Here is my script.


***************Start Script********************


echo off

Rem Delete any existing text files. Handy if rerunning the script.
Del C:\scripts\Test\*.txt

Rem Reboot the first box after 5 seconds and then sleeps for 5 minutes before checking the Netlogon service
shutdown -m \\WC0001 -r -f -t 5
sleep 300

Rem check and get the status of the Netlogon service and pipe the result into a text file saved with the server name
SC.exe \\WC0001 Query Kdc > c:\scripts\Test\WC0001.txt
Find /i "RUNNING" < c:\scripts\Test\WC0001.txt
IF "%ERRORLEVEL%"=="0" GOTO Srv1Online

:Srv1Offline
ECHO WC0001 is NOT Back online yet! >C:\scripts\Test\WC0001Offline.txt
GOTO END

:Srv1Online
shutdown -m \\WC0002 -r -f -t 30
sleep 300

SC.exe \\WC0002 Query Kdc > c:\scripts\Test\WC0002.txt
Find /i "RUNNING" < c:\scripts\Test\WC0002.txt
IF "%ERRORLEVEL%"=="0" GOTO Srv2Online

:Srv2Offline
ECHO WC0002 is NOT Back online yet! >C:\scripts\Test\WC1ADS11Offline.txt
GOTO END

:Srv2online
shutdown -m \\WC0003 -r -f -t 30
sleep 300

SC.exe \\WC0003 Query Kdc > c:\scripts\Test\WC0003.txt
Find /i "RUNNING" < c:\scripts\Test\WC0003.txt
IF "%ERRORLEVEL%"=="0" GOTO Srv3Online

and so on for more servers.

:END

***********************End Script*************************


Viewing all articles
Browse latest Browse all 15028

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>