Create a loop to set variable from text file and run batch
Posted: 25 Jul 2012 15:32
Hi guys,
Really trying to get to the bottom of this... I have written a short amateur batch file that simply pulls some basic system info and dumps it as a txt file... at the moment it prompts for human interaction with the user typing the name of the server and then the batch file referring to the info as a variable. What i want it to do it automatically read each line of the serverlist.txt file (which is full of server names that may have the "-" character in the name?) And then set this information as a variable to run the batch file
When it finishs i want it too loop through all the entries in the serverlist.txt and then stop!
Heres the code:
@ECHO OFF
CLS
mkdir C:\SERVER_AUDIT
c:
cd\SERVER_AUDIT
ECHO.
ECHO Server Info finder...
ECHO ======================
ECHO.
ECHO PRESS "1" TO READ A LIST OF SERVERS FROM SERVERLIST.TXT
ECHO.
ECHO PRESS "2" TO INPUT AN INDIVIDUAL SERVER
ECHO.
ECHO.
CHOICE /c:12
IF ERRORLEVEL 2 GOTO :SINGLE
IF ERRORLEVEL 1 GOTO :MULTIPLE
:SINGLE
:Start
set /p SERVER="Enter the name of the server - "
:pingtest
echo IP Address =>>%SERVER%.log
ping -n 1 %SERVER%>temp.log
findstr /i /c:"Reply from" temp.log>>%SERVER%.log
:ilotest
ping %SERVER%x>temp.log
findstr /i /c:"Reply From" temp.log
if %errorlevel% equ 1 goto notfound
echo iLO = Yes>>%SERVER%.log
goto done
:notfound
echo iLO = No >>%SERVER%.log
goto done
:done
:OSinfo
systeminfo /s %SERVER% /u .\Administrator /p somepassword /FO LIST>temp.log
findstr /i /c:"OS NAME" temp.log>>%SERVER%.log
findstr /i /c:"Domain" temp.log>>%SERVER%.log
findstr /i /c:"System Manafacturer" temp.log>>%SERVER%.log
findstr /i /c:"System Model" temp.log>>%SERVER%.log
findstr /i /c:"Host Name" temp.log>>%SERVER%.log
:serial
ECHO Server Serial Number:>>%SERVER%.log
wmic /USER:"%SERVER%\Administrator" /PASSWORD:"somepassword" /NODE:"%SERVER%" bios get serialnumber>>%SERVER%.log
Any ideas?
Although its not valid code... was sort of looking down this type of route...:
set SERVER=
for /f "delims=" %%i in ('type c:\server_audit\serverlist.txt') do call :start
Really trying to get to the bottom of this... I have written a short amateur batch file that simply pulls some basic system info and dumps it as a txt file... at the moment it prompts for human interaction with the user typing the name of the server and then the batch file referring to the info as a variable. What i want it to do it automatically read each line of the serverlist.txt file (which is full of server names that may have the "-" character in the name?) And then set this information as a variable to run the batch file
When it finishs i want it too loop through all the entries in the serverlist.txt and then stop!
Heres the code:
@ECHO OFF
CLS
mkdir C:\SERVER_AUDIT
c:
cd\SERVER_AUDIT
ECHO.
ECHO Server Info finder...
ECHO ======================
ECHO.
ECHO PRESS "1" TO READ A LIST OF SERVERS FROM SERVERLIST.TXT
ECHO.
ECHO PRESS "2" TO INPUT AN INDIVIDUAL SERVER
ECHO.
ECHO.
CHOICE /c:12
IF ERRORLEVEL 2 GOTO :SINGLE
IF ERRORLEVEL 1 GOTO :MULTIPLE
:SINGLE
:Start
set /p SERVER="Enter the name of the server - "
:pingtest
echo IP Address =>>%SERVER%.log
ping -n 1 %SERVER%>temp.log
findstr /i /c:"Reply from" temp.log>>%SERVER%.log
:ilotest
ping %SERVER%x>temp.log
findstr /i /c:"Reply From" temp.log
if %errorlevel% equ 1 goto notfound
echo iLO = Yes>>%SERVER%.log
goto done
:notfound
echo iLO = No >>%SERVER%.log
goto done
:done
:OSinfo
systeminfo /s %SERVER% /u .\Administrator /p somepassword /FO LIST>temp.log
findstr /i /c:"OS NAME" temp.log>>%SERVER%.log
findstr /i /c:"Domain" temp.log>>%SERVER%.log
findstr /i /c:"System Manafacturer" temp.log>>%SERVER%.log
findstr /i /c:"System Model" temp.log>>%SERVER%.log
findstr /i /c:"Host Name" temp.log>>%SERVER%.log
:serial
ECHO Server Serial Number:>>%SERVER%.log
wmic /USER:"%SERVER%\Administrator" /PASSWORD:"somepassword" /NODE:"%SERVER%" bios get serialnumber>>%SERVER%.log
Any ideas?
Although its not valid code... was sort of looking down this type of route...:
set SERVER=
for /f "delims=" %%i in ('type c:\server_audit\serverlist.txt') do call :start