Help with pinging servers, log failures
Moderator: DosItHelp
Help with pinging servers, log failures
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?
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?
Re: batch file help
try this:
Code: Select all
For /f %%A in (C:\Document.txt) Do Ping -n 2 %%A 2>&1 || >>PC.txt
Re: batch file help
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.
Re: batch file help
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
Re: batch file help
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
Re: Help with pinging servers, log failures
@foxidrive, can a computer name/URL contain white space?
Re: Help with pinging servers, log failures
No. It has to encode spaces as %20
I think a computername is only alphanumeric
I think a computername is only alphanumeric
Re: batch file help
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?
Re: batch file help
SPM wrote: >nul 1 | What does have mean?
- >nul = send standard output to "nul"
- || = in case of an error do
Re: batch file help
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?
Re: Help with pinging servers, log failures
the TYPE command.
Re: Help with pinging servers, log failures
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
Re: Help with pinging servers, log failures
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
Re: Help with pinging servers, log failures
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.
Re: Help with pinging servers, log failures
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" '
' type "C:\Document.txt" '
'"\\Server name\Document.txt" '