Hi all,
I have a batch file that pings a list of IP addresses. I need to send only the failed pings to a file.
Here's the batch file:
@Echo OFF
For /F "Usebackq Delims=" %%# in (
"List.txt"
) do (
Echo+
Echo [+] Pinging: %%#
Ping -n 1 "%%#" 1>nul && (
Echo [OK]) || (
Echo [FAILED])
)
Pause&Exit
The output looks like this, just showing two for example:
[+] Pinging: 172.17.219.133
[FAILED]
[+] Pinging: 172.28.145.199
[OK]
I need to edit the batch file to send the lines with the IP address of the failed pings to a file.
Is this possible?
Thanks in advance for your time and advice,
Eric
Edit bat file to parse strings and send output to file
Moderator: DosItHelp
Re: Edit bat file to parse strings and send output to file
Thanks. I added this line ahead of the For stuff:
>results.txt (
<the rest of the stuff>
)
PAUSE
That created the output file just fine. But I want to refince the output to only show the ones that failed, the two lines like this:
[+] Pinging: 172.17.219.133
[FAILED]
So that I have in the file a list of only those devices that aren't reachable.
>results.txt (
<the rest of the stuff>
)
PAUSE
That created the output file just fine. But I want to refince the output to only show the ones that failed, the two lines like this:
[+] Pinging: 172.17.219.133
[FAILED]
So that I have in the file a list of only those devices that aren't reachable.
Re: Edit bat file to parse strings and send output to file
Never mind, I just use Powershell commands to edit the file to show previous line.