Welcome guest. Before posting on our computer help forum, you must register. Click here it's easy and free.

Author Topic: Help with Batch file and Output  (Read 5185 times)

0 Members and 1 Guest are viewing this topic.

flainstigator

    Topic Starter


    Greenhorn

    Help with Batch file and Output
    « on: July 24, 2008, 02:40:31 PM »
    I am trying to write a batch file that will read 100's if IP's from a txt file, ping each one, then output the results to a file.  Each successive ping request/results should be appended to the same txt file.

    Help!!! please!!

    btw -using winxp pro.

    Dias de verano

    • Guest
    Re: Help with Batch file and Output
    « Reply #1 on: July 24, 2008, 02:48:25 PM »
    if exist pings.txt del pings.txt
    for /f %%I in (ips.txt) do ping %%I >> pings.txt




    erobby



      Beginner

      • Experience: Experienced
      • OS: Linux variant
      Re: Help with Batch file and Output
      « Reply #2 on: July 24, 2008, 06:34:18 PM »
      If you are pinging 100's of IP they expect a huge file.  Your output for each ping will be similar to this.

      Pinging yahoo.com [206.190.60.37] with 32 bytes of data:

      Reply from 206.190.60.37: bytes=32 time=60ms TTL=52
      Reply from 206.190.60.37: bytes=32 time=64ms TTL=52
      Reply from 206.190.60.37: bytes=32 time=60ms TTL=52
      Reply from 206.190.60.37: bytes=32 time=63ms TTL=52

      Ping statistics for 206.190.60.37:
          Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),
      Approximate round trip times in milli-seconds:
          Minimum = 60ms, Maximum = 64ms, Average = 61ms

      No you can narrow down you file by using -n options with ping ie like ping -n 1 to send one ping to the host -n 2 would send 2 pings and so on.

      Also you can use a find to limit the list like find /i "Reply" to find only machines that are replying to your ping request or a find /i "Pinging" so show every pinged address and whether it resolves or not

      flainstigator

        Topic Starter


        Greenhorn

        Re: Help with Batch file and Output
        « Reply #3 on: July 25, 2008, 06:21:59 AM »
        Thanks for the great replies, but it seems I am still having a problem that Imdomman was having with ping outputs.

        It works from a command line but not from the batch call.

        I have the file ips.txt with a single, pingable, address and here is what I get.

        Ping.bat -- >
        if exist pings.txt del pings.txt
        for /f %%I in (ips.txt) do ping %%I >> pings.txt

        Output-->
        C:\pings>if exist pings.txt del pings.txt
        C:\pings\pings.txt
        C:\pings>for /F %I in (ips.txt) do ping %I  1>>pings.txt
        C:\pings>ping 12.12.12.2  1>>pings.txt

        From a Command window I can type -->
        ping 12.12.12.2 >> pings12.txt

        Output  in pings12.txt-->
        Pinging 12.12.12.2 with 32 bytes of data:
        Reply from 12.12.12.2: bytes=32 time=127ms TTL=234
        Reply from 12.12.12.2: bytes=32 time=125ms TTL=235
        Reply from 12.12.12.2: bytes=32 time=144ms TTL=235
        Reply from 12.12.12.2: bytes=32 time=124ms TTL=234

        Ping statistics for 12.12.12.2:
            Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),

        Approximate round trip times in milli-seconds:
            Minimum = 124ms, Maximum = 144ms, Average = 130ms

        So anyone know what the 1 is or what is causing it??

        Also, when I run the complete list of IPs, I get a message in the command window that says the process cannot access the file because it is being used by another process.

        Dias de verano

        • Guest
        Re: Help with Batch file and Output
        « Reply #4 on: July 25, 2008, 06:41:02 AM »
        start your batch file with this line

        @echo off

        flainstigator

          Topic Starter


          Greenhorn

          Re: Help with Batch file and Output
          « Reply #5 on: July 25, 2008, 06:55:51 AM »
          With @ Echo off the output in my ping.txt file is -->

          C:\pings\pings.txt

          Without @ Echo the output in my ping.txt file is  -->

          C:\pings>if exist pings.txt del pings.txt
          C:\pings\pings.txt
          C:\pings>for /F %I in (ips.txt) do ping %I  1>>pings.txt
          C:\pings>ping 12.12.12.2  1>>pings.txt

          The ever-present 1 again....

          flainstigator

            Topic Starter


            Greenhorn

            Re: Help with Batch file and Output
            « Reply #6 on: July 25, 2008, 07:07:31 AM »
            FYI.. I figured out the process sharing violation.  It is because the batch file was named PING and PING is also a command, so I think I was confusing it.  When I changed the filename to PINGBAT.bat it started to work without the sharing violation.

            Now I am waiting on the results of the complete run, and will post when complete.

            Dias de verano

            • Guest
            Re: Help with Batch file and Output
            « Reply #7 on: July 25, 2008, 07:09:04 AM »
            that 1 you saw is normal.

            flainstigator

              Topic Starter


              Greenhorn

              Re: Help with Batch file and Output
              « Reply #8 on: July 25, 2008, 07:22:26 AM »
              Also you can use a find to limit the list like find /i "Reply" to find only machines that are replying to your ping request or a find /i "Pinging" so show every pinged address and whether it resolves or not

              Where would I use this switch in the command/bat file?

              flainstigator

                Topic Starter


                Greenhorn

                Re: Help with Batch file and Output
                « Reply #9 on: July 25, 2008, 07:23:41 AM »
                Now I am waiting on the results of the complete run, and will post when complete.

                Thanks for all the help!!  The basic file runs complete now.  Now to tinker and see what else I can do to streamline the outputs.

                Dias de verano

                • Guest
                Re: Help with Batch file and Output
                « Reply #10 on: July 25, 2008, 07:39:25 AM »
                Also you can use a find to limit the list like find /i "Reply" to find only machines that are replying to your ping request or a find /i "Pinging" so show every pinged address and whether it resolves or not

                Where would I use this switch in the command/bat file?

                @echo off
                if exist pings.txt del pings.txt
                for /f %%I in (ips.txt) do (
                    ping -n 1 %%I | find /i "Reply" >> pings.txt
                    )


                flainstigator

                  Topic Starter


                  Greenhorn

                  Re: Help with Batch file and Output
                  « Reply #11 on: July 25, 2008, 07:47:36 AM »
                  THANKS - You all ROCK. 

                  Saved me tons of time and angst!!!

                   ;D

                  erobby



                    Beginner

                    • Experience: Experienced
                    • OS: Linux variant
                    Re: Help with Batch file and Output
                    « Reply #12 on: July 25, 2008, 06:01:52 PM »
                    Also you can use a find to limit the list like find /i "Reply" to find only machines that are replying to your ping request or a find /i "Pinging" so show every pinged address and whether it resolves or not

                    Where would I use this switch in the command/bat file?

                    @echo off
                    if exist pings.txt del pings.txt
                    for /f %%I in (ips.txt) do (
                        ping -n 1 %%I | find /i "Reply" >> pings.txt
                        )



                    for /f  %%b in ('ping -n 2 -a %*^| find /i "Pinging"') do echo %%b >> pings.txt

                    Same thing just one line