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

Author Topic: Ping bat file  (Read 24121 times)

0 Members and 2 Guests are viewing this topic.

seth001

    Topic Starter


    Greenhorn

    Ping bat file
    « on: April 07, 2009, 03:25:41 AM »
    Hallo,

    I want to make a bat file that performs a ping action.
    If the result is request time out than the bat file time.bat has to be activated. The time.bat enters the time that the ping action has failed.
    EXAMPLE of ping.bat:
    :start
    ping www.google.nl -n 20 
    (After this I don’t now what to do?)
    CALL time.bat
    GOTO start


    EXAMPLE of time.bat:
    echo.|TIME >> C:\ping\Data.txt (the time will be enter in the text file Data.txt

    Can somebody help me with a function that will activate the time.bat only when there is a request time out?

    Dias de verano

    • Guest
    Re: Ping bat file
    « Reply #1 on: April 07, 2009, 05:49:04 AM »
    Code: [Select]
    :start
    ping www.whatever.com - n 20 | find "Request timed out." && (
            call time.bat
            )
    goto start

    jrebazap

    • Guest
    Re: Ping bat file
    « Reply #2 on: April 07, 2009, 06:04:24 AM »
    Hi there

    Try this code:

    @echo off
    :start
    ping www.google.nl -n 20 |findstr ms$
    if not errorlevel 1 goto start
    echo %date% %time% >> ping_log.txt
    goto start

    The last part of line 3 (|findstr ms$) is just to stop getting the whole response in the screen if you run the batch in DOS. You'll get only the very last line of the summary after the 20 pings.

    In line 5 an alternative to record date and time to a log file, only if ping fails with timeout. If ping does not fail line 4 will go to :start .

    Good luck

    seth001

      Topic Starter


      Greenhorn

      Re: Ping bat file
      « Reply #3 on: April 07, 2009, 07:07:20 AM »
      The error I get is, when the bat file starts I only see ping
      www.whatever.com - n 20 | find "Request timed out." && (call time.bat). That line get repeated  the whole time? So in steed that the ping action is activated only the line is repeated  ? ???

      Dias de verano

      • Guest
      Re: Ping bat file
      « Reply #4 on: April 07, 2009, 08:05:20 AM »
      The error I get is, when the bat file starts I only see ping
      www.whatever.com - n 20 | find "Request timed out." && (call time.bat). That line get repeated  the whole time? So in steed that the ping action is activated only the line is repeated  ? ???


      Please post the code you are using.

      seth001

        Topic Starter


        Greenhorn

        Re: Ping bat file
        « Reply #5 on: April 07, 2009, 08:25:19 AM »
        I have created a bat file named test.
        Test.bat contains :
        Code: [Select]
        :start
        ping www.whatever.com - n 20 | find "Request timed out." && (call time.bat)
        goto start

        Time.bat contains :
        Code: [Select]
        echo %date% %time% >> c:\ping\time.txt

        But the problem is that test.bat doesn’t go further than the line ping www.whatever.com - n 20 | find "Request timed out." && (call time.bat), so the ping function never gets activated.
        When I do the same line ( ping www.whatever.com - n 20 | find "Request timed out." && (call time.bat) ) in RUN, CMD the ping session starts and writes the date and time of the request time out message.

        Dias de verano

        • Guest
        Re: Ping bat file
        « Reply #6 on: April 07, 2009, 08:37:57 AM »
        Code: [Select]
        :start
        ping www.whatever.com - n 20 | find "Request timed out." && (call time.bat)
        goto start

        I just tried this code in a batch using www.bbc.co.uk (which does not service ping requests) and it tried to ping 20 times then called time.bat then started all over again. It's doing it right now.

        [update]

        10 minutes later, it's still doing it.

        I actually intended www.whatever.com to be a placeholder for whatever host you really wanted to use, but I just discovered it actually exists and also does not service ping requests.


        « Last Edit: April 07, 2009, 08:51:34 AM by Dias de verano »

        Dias de verano

        • Guest
        Re: Ping bat file
        « Reply #7 on: April 07, 2009, 08:53:02 AM »
        Does your silence mean you found your mistake?

        seth001

          Topic Starter


          Greenhorn

          Re: Ping bat file
          « Reply #8 on: April 07, 2009, 09:17:18 AM »
          Sorry for not responding right away, no I didn’t find the problem I was away from my desk. But seeing it worked for you, why can agree on the code works and that I mistyped something. I will look for the problem tomorrow and post it if I find it. Thank your very much for your time and help!

          Dias de verano

          • Guest
          Re: Ping bat file
          « Reply #9 on: April 07, 2009, 09:23:01 AM »
          Alternative code. Change the 1 to however many attempts you want to try each time.

          Code: [Select]
          @echo off
          :loop
          ping www.whatever.com -n 1
          if %errorlevel% GTR 0 call time.bat
          goto loop

          PS it is considered bad practice to name a batch file the same as a command (time).

          gh0std0g74



            Apprentice

            Thanked: 37
            Re: Ping bat file
            « Reply #10 on: April 07, 2009, 09:24:30 AM »
            Does your silence mean you found your mistake?

            you sound like those guys that post a question and couldn't wait for an answer to return and keep asking who's gonna help him.

            seth001

              Topic Starter


              Greenhorn

              Re: Ping bat file
              « Reply #11 on: April 08, 2009, 07:08:59 AM »
              I activated the bat file again today still no success. After that I created a new folder and put both bat file there (the last folder there were 9 different bat files). I run it again this time with success!

              Dias de verano

              • Guest
              Re: Ping bat file
              « Reply #12 on: April 08, 2009, 07:20:32 AM »
              the last folder there were 9 different bat files

              Was one of them called ping.bat?

              seth001

                Topic Starter


                Greenhorn

                Re: Ping bat file
                « Reply #13 on: April 08, 2009, 07:32:14 AM »
                No, but every time I changed the content of the bat file I didn’t see the change (example I changed the Ip address in 127.0.0.1 but it still goes to www.whatever.com)
                Than I created a new folder and moved the bat file there. After the changes of folders, the bat file works.

                Dias de verano

                • Guest
                Re: Ping bat file
                « Reply #14 on: April 08, 2009, 07:35:26 AM »
                maybe you were saving your changed .bat to a different folder.

                Helpmeh



                  Guru

                • Roar.
                • Thanked: 123
                  • Yes
                  • Yes
                • Computer: Specs
                • Experience: Familiar
                • OS: Windows 8
                Re: Ping bat file
                « Reply #15 on: April 08, 2009, 03:43:53 PM »
                No, but every time I changed the content of the bat file I didn’t see the change (example I changed the Ip address in 127.0.0.1 but it still goes to www.whatever.com)
                Than I created a new folder and moved the bat file there. After the changes of folders, the bat file works.


                I personally ping LOCALHOST instead of 127.0.0.1, although they do the same thing (HOSTS file).
                Where's MagicSpeed?
                Quote from: 'matt'
                He's playing a game called IRL. Great graphics, *censored* gameplay.

                daywalkerz

                • Guest
                Re: Ping bat file
                « Reply #16 on: November 27, 2009, 12:46:27 PM »
                Hallo,

                I want to make a bat file that performs a ping action.
                If the result is request time out than the bat file time.bat has to be activated. The time.bat enters the time that the ping action has failed.
                EXAMPLE of ping.bat:
                :start
                ping www.google.nl -n 20 
                (After this I don’t now what to do?)
                CALL time.bat
                GOTO start


                EXAMPLE of time.bat:
                echo.|TIME >> C:\ping\Data.txt (the time will be enter in the text file Data.txt

                Can somebody help me with a function that will activate the time.bat only when there is a request time out?


                hii there..im just newbe here...hope this will solve your problems.
                try this code:
                Code: [Select]
                @echo off
                color 0A
                title PING TEST By DAYWALKERZ
                echo.
                echo.
                :start
                echo. >> C:\ping\Data.txt
                echo. TIME>> C:\ping\Data.txt
                echo  Date: %date%  Time:%time% *START PING >> C:\ping\Data.txt
                echo.
                echo STARTING PING TEST...
                echo *********************
                echo.
                echo Date: %date% 
                echo Time: %time%
                ping google.nl -n 4 |find "Request timed out." && (goto A)
                ping localhost -n 60 >nul
                goto start
                :A
                echo  Date: %date%  Time: %time% *PING FAILED >> C:\ping\Data.txt
                ping localhost -n 30 >nul
                goto start

                ok here the tips.

                1st - make sure that you make empty folder on where ever location on your hardrive that called "ping"
                example:
                Code: [Select]
                C:\ping
                2nd - dont put the www infront of the ping site
                example:
                Code: [Select]
                ping google.nl
                3rd - do not ping to long...waste a time ... just make short pings only.
                example:
                Code: [Select]
                ping google.nl -n 4
                4th - timer for every pings. here i set it for 60 sec every ping.you may set it what ever you liked.
                example:
                Code: [Select]
                ping localhost -n 60 >nul
                5th - call or goto, if you call its will popup or runs what you have set.you also may change it what ever you wants.
                example:
                Code: [Select]
                |find "Request timed out." && (goto A)
                - if you wanna call your file such "time.bat"...just change it to "CALL time.bat".but make sure you already make batch file for "time.bat" and make sure you get it full location of it.
                example:
                Code: [Select]
                |find "Request timed out." && (CALL C:\time.bat)

                sample picture:

                cmd:


                log file:


                hopefully will help you solve your problems....
                sorry for my broken language...

                Salmon Trout

                • Guest
                Re: Ping bat file
                « Reply #17 on: November 27, 2009, 12:51:20 PM »
                hii there..im just newbe here...hope this will solve your problems.

                This thread died 7 months ago!