none
Trying to create a batch file that pings a list of IP address and only outputs fails RRS feed

  • Question

  • Hello,

    i am quite new to creating batch files but in my line of work i am required to ping alot of machines on a daily basis.

    i have copied a previous batch file i found on here which is working fantastic. However i am wanting to edit it to only output if the ping failed. i have googled around but i am unable to find the write strings to change the output to just output fails to the txt file.
    See below

    @echo off

    Echo pingtest executed on %date% at %time% > c:\pingtest\output.txt
    Echo == >> c:\pingtest\output.txt
    for /f %%i in C:\pingtest\input.txt to call :sub %%i
    Notepad c:\pingtest\output.txt

    goto :eof

    :sub
    echo testing %1

    Set state=alive
    ping -n 1 %1
    if errorlevel 1 set state=dead
    Echo %1 is %state% >> c:\pingtest\output.txt


    • Moved by Bill_Stewart Monday, July 29, 2019 7:55 PM This is not "scripts on demand"
    Sunday, December 2, 2018 1:23 PM

All replies

  • Batch files are obsolete you should not be using them.  PowerShell is the replacement for the old shell.

    Also note that this forum is not for customizing scripts (or batch files) you have found on the Internet.  The forum is for technicians who use scripting.

    If you look in the Gallery you will find many scripts that do what you are trying to do.  Choose one of those pre-written scripts.


    \_(ツ)_/

    • Proposed as answer by BOfH-666 Sunday, December 2, 2018 7:11 PM
    Sunday, December 2, 2018 5:31 PM