Help with pinging servers, log failures

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Message
Author
SPM
Posts: 7
Joined: 17 Jun 2013 08:02

Help with pinging servers, log failures

#1 Post by SPM » 17 Jun 2013 08:13

Hey guys looking for some help on the below script. So here is what i'm trying to do, Ping 20-30 PC from a text file, Output the Time Out to a file.

Here is what I have, which works just stuck on the Timeout section.

For /f %%A in (C:\Document.txt) Do Ping -n 2

Now if I do For /f %%A in (C:\Document.txt) Do Ping -n 2 >>PC.txt

This will output every response which I only need the PC's that are offline. Been playing with For /f %%A in (C:\Document.txt) Do Ping -n 2 |findstr Reply') >>PC.txt


Any advice?

Endoro
Posts: 244
Joined: 27 Mar 2013 01:29
Location: Bozen

Re: batch file help

#2 Post by Endoro » 17 Jun 2013 08:24

try this:

Code: Select all

For /f %%A in (C:\Document.txt) Do Ping -n 2 %%A 2>&1 || >>PC.txt 

SPM
Posts: 7
Joined: 17 Jun 2013 08:02

Re: batch file help

#3 Post by SPM » 17 Jun 2013 08:28

Endoro wrote:try this:

Code: Select all

For /f %%A in (C:\Document.txt) Do Ping -n 2 %%A 2>&1 || >>PC.txt 


thanks Endoro but no luck.

Endoro
Posts: 244
Joined: 27 Mar 2013 01:29
Location: Bozen

Re: batch file help

#4 Post by Endoro » 17 Jun 2013 08:52

test this, also with your PC's

Code: Select all

ping google.com -n 1 && echo success || echo FAILURE
ping google.gov -n 1 && echo success || echo FAILURE

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: batch file help

#5 Post by foxidrive » 17 Jun 2013 09:06

Code: Select all

@echo off
For /f "delims=" %%a in (' type "C:\Document.txt" ') do Ping -n 2 %%a >nul || echo %%a offline>>PC.txt

Endoro
Posts: 244
Joined: 27 Mar 2013 01:29
Location: Bozen

Re: Help with pinging servers, log failures

#6 Post by Endoro » 17 Jun 2013 09:38

@foxidrive, can a computer name/URL contain white space?

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Help with pinging servers, log failures

#7 Post by foxidrive » 17 Jun 2013 10:00

No. It has to encode spaces as %20

I think a computername is only alphanumeric

SPM
Posts: 7
Joined: 17 Jun 2013 08:02

Re: batch file help

#8 Post by SPM » 17 Jun 2013 11:17

foxidrive wrote:

Code: Select all

@echo off
For /f "delims=" %%a in (' type "C:\Document.txt" ') do Ping -n 2 %%a >nul || echo %%a offline>>PC.txt


Perfect this is just want i need it.

Since i'm here to learn let ask >nul 1 | What does have mean?

Endoro
Posts: 244
Joined: 27 Mar 2013 01:29
Location: Bozen

Re: batch file help

#9 Post by Endoro » 17 Jun 2013 11:31

SPM wrote: >nul 1 | What does have mean?


- >nul = send standard output to "nul"
- || = in case of an error do

SPM
Posts: 7
Joined: 17 Jun 2013 08:02

Re: batch file help

#10 Post by SPM » 17 Jun 2013 14:06

foxidrive wrote:

Code: Select all

@echo off
For /f "delims=" %%a in (' type "C:\Document.txt" ') do Ping -n 2 %%a >nul || echo %%a offline>>PC.txt



One last question, the above command works great pulling the document from the local C: Drive. Having problems running it from a Network Shared. For /f "delims=" %%a in ('"\\Server name\Document.txt" ') do Ping -n 2 %%a >nul || echo %%a offline>>PC.txt

What am I missing?

Squashman
Expert
Posts: 4488
Joined: 23 Dec 2011 13:59

Re: Help with pinging servers, log failures

#11 Post by Squashman » 17 Jun 2013 15:05

the TYPE command.

SPM
Posts: 7
Joined: 17 Jun 2013 08:02

Re: Help with pinging servers, log failures

#12 Post by SPM » 19 Jun 2013 06:59

Squashman wrote:the TYPE command.


@echo off
Should I do Type \\Sever path\ For /f "delims=" %%a in (' type "C:\Document.txt" ') do Ping -n 2 %%a >nul || echo %%a offline>>PC.txt

Squashman
Expert
Posts: 4488
Joined: 23 Dec 2011 13:59

Re: Help with pinging servers, log failures

#13 Post by Squashman » 19 Jun 2013 08:23

Compare the code foxidrive gave you to the code you are trying to use. Can you not SEE where the TYPE command is!

Code: Select all

For /f "delims=" %%a in (' type "C:\Document.txt" ') do Ping -n 2 %%a >nul || echo %%a offline>>PC.txt

For /f "delims=" %%a in ('"\\Server name\Document.txt" ') do Ping -n 2 %%a >nul || echo %%a offline>>PC.txt

SPM
Posts: 7
Joined: 17 Jun 2013 08:02

Re: Help with pinging servers, log failures

#14 Post by SPM » 19 Jun 2013 08:48

Squashman wrote:Compare the code foxidrive gave you to the code you are trying to use. Can you not SEE where the TYPE command is!

Code: Select all

For /f "delims=" %%a in (' type "C:\Document.txt" ') do Ping -n 2 %%a >nul || echo %%a offline>>PC.txt

For /f "delims=" %%a in ('"\\Server name\Document.txt" ') do Ping -n 2 %%a >nul || echo %%a offline>>PC.txt



As you can tell in my earlier post ( For /f "delims=" %%a in ('"\\Server name\Document.txt" ') do Ping -n 2 %%a >nul || echo %%a offline>>PC.txt) that does not work. I can output to the server but can't have it call for the document.

Squashman
Expert
Posts: 4488
Joined: 23 Dec 2011 13:59

Re: Help with pinging servers, log failures

#15 Post by Squashman » 19 Jun 2013 09:02

What is the different between these two commands? It should be pretty obvious. HINT: TYPE is MISSING!!!!!!!!!!!

' type "C:\Document.txt" '
'"\\Server name\Document.txt" '

Post Reply