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