FOR LOOP Understanding (Am new to this :-O)

June 21, 2011 at 06:16:22
Specs: Windows 7
Hi All,

I'm very new to this and am finding my way through :)

I can read my .txt. file containing a list of PC's which I need to ping to check they are alive. I need to record this into a csv file called ping.csv but heres the thing how do I then add another 'for loop' to read the new ping.csv pc list and then loop through that.

I have tried this but it looks like the batch is looping through both loops one after the other I need it to complete one loop first record the result and then complete the other loop recording different results.

This is what I have (I know it may not be the best approach)

@echo on

set service=tmlisten
set state=STOPPED
set list=pcpinglist.txt
set date=%date%
set time=%time%
set log1=pingtest.csv
set log2=tmlistenstatus.csv

if not exist "c:\downloads\rox\tmlistencheck\%log1%" echo Computer,Source_IP>"c:\downloads\rox\tmlistencheck\%log1%"
if not exist "c:\downloads\rox\tmlistencheck\%log2%" echo Computer,Date,Time,%service% Status>"c:\downloads\rox\tmlistencheck\%log2%"

REM Ping Offline Clients

for /F %%G in (c:\downloads\rox\tmlistencheck\%list%) do (
for /F "tokens=1 delims=" %%P in ('ping -n 1 %%G ^| findstr="Reply"') do (
echo %%G,%%P >>"c:\downloads\rox\tmlistencheck\%log1%")
goto checkservice

REM Check Service Status
for /F %%C in ('type "c:\downloads\rox\tmlistencheck\%log1%"') do (
for /F "tokens=3 delims=: " %%H in ('sc \\%%G query "%service%" ^| findstr "STATE"') do (
echo %%C,%date%,%time%,%%H>>"c:\downloads\rox\tmlistencheck\%log2%"


See More: FOR LOOP Understanding (Am new to this :-O)

Report •

June 21, 2011 at 06:49:22
OK so I think I got this working....I misplaced a closed bracket from the look of things.....Ouch !!! :D

Any advice that pops out to you ... well am here to learn...Thanks ALL :)

Report •
Related Solutions

Ask Question