DosTips.com

A Forum all about DOS Batch
It is currently 08 Feb 2016 06:18

All times are UTC-06:00




Post new topic  Reply to topic  [ 7 posts ] 
Author Message
PostPosted: 25 Jul 2012 15:32 
Offline

Joined: 04 Apr 2012 03:11
Posts: 38
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


Top
   
PostPosted: 25 Jul 2012 15:40 
Offline

Joined: 23 Dec 2011 13:59
Posts: 2979
You don't need to use the type command. That is what the /F switch is for.
Code:
for /f "delims=" %%i in (c:\server_audit\serverlist.txt) do call :start %%i


Top
   
PostPosted: 25 Jul 2012 18:23 
Offline

Joined: 04 Apr 2012 03:11
Posts: 38
Thanks Squashman, I dont believe that my line of code is right though reagardless of the correction as it seems that i need to set the variable %SERVER% to a line from the serverlist.txt file and then run through the whole batch file. When thats finished it needs to do the same thing with every line in the serverlist.txt


Top
   
PostPosted: 25 Jul 2012 18:39 
Offline

Joined: 23 Dec 2011 13:59
Posts: 2979
When you use CALL the way I am doing it, the sub routine inherits the %%I variable. You can then reference it as %1 in your CALLed sub routine.

So at the beginning of the START subroutine just do a set statement
SET server=%1


Top
   
PostPosted: 26 Jul 2012 01:56 
Offline

Joined: 04 Apr 2012 03:11
Posts: 38
I see what you mean -- That seems to have worked!

Thanks so much!


Top
   
PostPosted: 05 Aug 2012 23:37 
Offline

Joined: 23 Jul 2012 12:09
Posts: 8
Hey I'm trying to do this as well
It does everything fine.
It can read the first line of a text file and use that
But im not understanding how to go to the next line after i have done what I need to.
There are sub routines, does this make a difference?


Top
   
PostPosted: 06 Aug 2012 03:30 
Offline

Joined: 10 Feb 2012 02:20
Posts: 5355
This is a skeleton to show you the sequence and where to continue your batch file

Code:
@echo off
for /f "delims=" %%i in (c:\server_audit\serverlist.txt) do call :start %%i
rem do your next commands here
pause
goto :EOF

:start
rem the loop commands go here
end of batch file


Top
   
Display posts from previous:  Sort by  
Post new topic  Reply to topic  [ 7 posts ] 

All times are UTC-06:00


Who is online

Users browsing this forum: Baidu [Spider], Google [Bot], Yahoo [Bot] and 19 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Limited