Solved Need help creating Batch file

June 26, 2012 at 06:52:06
Specs: Windows 7
I've created a batch file that pings a set of computers and puts the results in a text file. Now I want to change it from putting all of the results into the file to just the time outs.

Here is what I have so far:

set d=%date:~-4,4%%date:~-7,2%%date:~0,2%
set d=%d: =_%
set t=%time:~0,2%%time:~3,2%%time:~6,2%
set t=%t: =0%


RENAME "C:\Users\mobile\Documents\Readers\Reader_results.txt" "Reader_Results_%d%_%t%.TXT"

move /-y "C:\Users\mobile\Documents\Readers\*.txt" "C:\Users\joseph.santelmann\Documents\Readers\Past Reader Results"

For /f %%v in (C:\Users\mobile\Documents\Readers\myIPs.rtf) do ping %%v >> Reader_results.txt

Any help is appreciated!


See More: Need help creating Batch file

Report •

✔ Best Answer
June 26, 2012 at 12:32:01
This should also work:
For /f %%v in (C:\Users\mobile\Documents\Readers\myIPs.rtf) do ping -n 2 -w 500 %%v>nul ||>> Reader_results.txt echo %%v
:end
(this puts only the ip or hostname into the failed file, and speeds things up with the ping options given. I've always considered the connection either unreliable or non-existant when i get any missed ping within about a half second, but that's just me.)



#1
June 26, 2012 at 07:43:40
I think this should work, please test.

For /f %%v in (C:\Users\mobile\Documents\Readers\myIPs.rtf) do PING |find "TTL=" || >> Reader_results.txt

:: mike


Report •

#2
June 26, 2012 at 10:10:19
I got a syntax error

Report •

#3
June 26, 2012 at 10:25:40
sorry i left out

do PING %%v |find "TTL=" || >> Reader_results.txt

:: mike


Report •

Related Solutions

#4
June 26, 2012 at 12:19:41
I tried that but I still got a syntax error.

Here is what I have:

set d=%date:~-4,4%%date:~-7,2%%date:~0,2%
set d=%d: =_%
set t=%time:~0,2%%time:~3,2%%time:~6,2%
set t=%t: =0%


RENAME "C:\Users\mobile\Documents\Readers\Reader_results.txt" "Reader_Results_%d%_%t%.TXT"

move /-y "C:\Users\mobile\Documents\Readers\*.txt" "C:\Users\joseph.santelmann\Documents\Readers\Past Reader Results"

For /f %%v in (C:\Users\mobile\Documents\Readers\myIPs.rtf) do PING %%v |find "TTL=" || >> Reader_results.txt

I don't know if this helps but I tried removing the part starting with 'For' and puttting in its own file. When I ran it all it did was bring up the command prompt, display the file path and close.


Report •

#5
June 26, 2012 at 12:32:01
✔ Best Answer
This should also work:
For /f %%v in (C:\Users\mobile\Documents\Readers\myIPs.rtf) do ping -n 2 -w 500 %%v>nul ||>> Reader_results.txt echo %%v
:end
(this puts only the ip or hostname into the failed file, and speeds things up with the ping options given. I've always considered the connection either unreliable or non-existant when i get any missed ping within about a half second, but that's just me.)


Report •

#6
June 26, 2012 at 13:38:17
It works! Thanks so much. Can you explain to me each part to me, especially the part of do?

Report •

#7
June 26, 2012 at 19:08:40
ping -n 2 -w 500 %%v>nul ||>> Reader_results.txt echo %%v

the ping options are explained by ping.exe /?: in this case, ping 2 times, and only
wait 1/2 second (500 milisecs) for reply.
The ping output is sent to nul (ie: "nowhere", "the dead zone", limbo) since it's not really needed. The double-pipe is a logical OR based on the errorlevel output of the ping command (when ping fails, it sets erlvl > 0). So, if ping fails to get a reply, the ip or hostname appends to results.txt.
Double ampersands (&&) means AND, double pipes means OR. AND is executed if the upstream pipe-command errorlevel is zero, OR is executed if not zero. They can both be used in one command, like: ping %%v && echo success %%v|| echo failed %%v
but I think the "ands" have to come first for this to work.


Report •

#8
June 28, 2012 at 07:04:35
What are the -n and -w for?

Report •

#9
June 28, 2012 at 08:43:23
-n count Number of echo requests to send.
-w timeout Timeout in milliseconds to wait for each reply.

so in this case it means two requests with a half second timeout.

:: mike


Report •

Ask Question