|
Answer» Hi all I want to restart a package of machines located in text file Through the below steps: - Firstly ping for each one of them . -IF the hosname is available - Create a random NUMBER between 0 and 15 seconds and store it in a VARIABLE. - Execute the remote shutdown command usinge a random timeout stored in the PREVIOUS variable. - Store the result in an output file "Result.txt" in the same folder. -IF the hostname is not available - Also store the result in an output file "Result.txt" in the same folder.
here is my batch file content echo off for /f %%H in (hosts.txt) do ( echo %%H ping -n 1 -l 32 -w 2000 -i 32 %%H >nul echo %errorlevel% pause IF %ERRORLEVEL%==0 ( set /a "rand=(%RANDOM%*15/32768)+1" echo %rand% shutdown -r -t %rand% -c "Made by Eng Amin" -f -m \\%%H echo.[%%H is restarted]>>Result.txt ) IF %ERRORLEVEL%==1 echo.[%%H is --- Offline]>>Result.txt )
and this is the content of the hosts.txt and located in the same directory C3I3C331 C3I3C332 C3I3C333 C3I3C334
by the way I'm still beginner Can any one advice , CORRECT my code and till me where is the bug Hi All
Kindly don't ignore my question and Can anyone help me, please?
I want to restart any pc over my network using the shutdown command with a random timeout between 1 to 15 seconds.
Ex. shutdown -r -f -t %random time from 1 to 15 sec% %hostname Or Ip% as it didn't work with me ever My point here is to give any pc a random timeout for shutdown command as all PCs included in a text file and I will use for LOOP to pass through them and if you know a better solution kindly help
|