none
Script to tracert multiple computer names and find specifc text RRS feed

  • Question

  • I'm looking for a script to tracert multiple servers and find a specific text in tracert output and get output as csv.
    Below is what I have:

    @ECHO OFF
    FOR /F %%S IN (SERVERS.TXT) DO (
    ECHO %%S >> OUTPUT.LOG
    TRACERT %%S | Findstr "firewall -f-" >> output.log
    )

    Above script gives below output:

    server1
      4     1 ms    <1 ms    <1 ms  site1firewall [10.2.2.1] 
    server2 
      4     1 ms    <1 ms    <1 ms  site2firewall [10.2.22.1] 
    server3

    I want to tweak this script:

    1. Verify if server is alive/accessible before running tracert
    2. Output in table format (in single line)

    Can somebody help?

    Thanks.


    • Edited by Justin_D Thursday, July 17, 2014 7:08 AM
    Thursday, July 17, 2014 7:04 AM

Answers

  • Here you go:

    @ECHO OFF
    echo Script run on %date% at %time% >
    output.log
    FOR /F %%S IN (SERVERS.TXT) DO (

       for /F %%a in ('echo %%S') do <nul>>output.log set /p =%%a
       TRACERT %%S | Findstr "firewall -f-" >> output.log
    )

    Thursday, July 17, 2014 10:36 AM
  • The code does exactly what you asked for:

    1. It writes the machine name to the output file, without a CRLF.
    2. It writes the output from the tracert command to the output file, with a CRLF. When the tracert command generates no output (because it cannot reach the target machine) then it writes nothing, not even a CRLF.

    You must now add some code that distinguishes between responding and non responding machines, e.g. by pinging the target machine before issuing the tracert command.

    Friday, August 1, 2014 6:06 AM

All replies

  • Use ping.exe to find out if the targeted server is alive.

    Use this code to get your output on a single line:
    @ECHO OFF
    FOR /F %%S IN (SERVERS.TXT) DO (
       for /F %%a in ('echo %%S') do <nul>output.log set /p =%%a
       TRACERT %%S | Findstr "firewall -f-" >> output.log
    )

    Thursday, July 17, 2014 7:34 AM
  • Hi Frederik,

    Thanks for the quick response, however above code didn't produce any output other than 1st computer name in the servers.txt file

    Could you review again and also is it possible to combine ping action also in this batch file?

    Thanks.

    Justin.

    Thursday, July 17, 2014 9:58 AM
  • Here you go:

    @ECHO OFF
    echo Script run on %date% at %time% >
    output.log
    FOR /F %%S IN (SERVERS.TXT) DO (

       for /F %%a in ('echo %%S') do <nul>>output.log set /p =%%a
       TRACERT %%S | Findstr "firewall -f-" >> output.log
    )

    Thursday, July 17, 2014 10:36 AM
  • Thanks, almost there, only thing missing is formatting, in spite of getting in next lines, outputs all are saved in same line.

    If this could be fixed, that would be perfect.

    Thanks.

    Thursday, July 31, 2014 10:44 AM
  • If this could be fixed, that would be perfect.

    Please do this:

    • Post a sample of the output you get.
    • Try to respond a little more quickly than after two full weeks.
    Thursday, July 31, 2014 2:03 PM
  • Hi Frederik,

    Sample output below:

    Script run on 01/08/2014 at  4:17:35.00 
    server32server02server001server330 11   121 ms   121 ms   121 ms  site-f-101-eth1.domain.com [16.94.195.13] 

    server15server48server35server38server109server638server4server63

    Hope not too delay this time :)

    Thx.

    Friday, August 1, 2014 2:53 AM
  • The code does exactly what you asked for:

    1. It writes the machine name to the output file, without a CRLF.
    2. It writes the output from the tracert command to the output file, with a CRLF. When the tracert command generates no output (because it cannot reach the target machine) then it writes nothing, not even a CRLF.

    You must now add some code that distinguishes between responding and non responding machines, e.g. by pinging the target machine before issuing the tracert command.

    Friday, August 1, 2014 6:06 AM
  • Thanks, let me try figure-out.
    Friday, August 1, 2014 7:20 AM