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

Author Topic: batch file for tracert  (Read 16168 times)

0 Members and 1 Guest are viewing this topic.

vkkhurava

    Topic Starter


    Starter

    • Experience: Beginner
    • OS: Windows 7
    batch file for tracert
    « on: May 07, 2014, 08:18:08 AM »
    Hi,

    Can someone help me creating a tracert batch file which run conti after 1 or 3 hr and print tracert report with different file name & date, time stamp, so that previously created tracert report not get merged.

    foxidrive



      Specialist
    • Thanked: 268
    • Experience: Experienced
    • OS: Windows 8
    Re: batch file for tracert
    « Reply #1 on: May 07, 2014, 08:32:49 AM »
    Your question doesn't have all the details but see if this works for you:

    Code: [Select]
    @echo off
    :loop

    for /f "tokens=2 delims==" %%a in ('wmic OS Get localdatetime /value') do set "dt=%%a"
    set "YY=%dt:~2,2%" & set "YYYY=%dt:~0,4%" & set "MM=%dt:~4,2%" & set "DD=%dt:~6,2%"
    set "HH=%dt:~8,2%" & set "Min=%dt:~10,2%" & set "Sec=%dt:~12,2%"

    set "datestamp=%YYYY%%MM%%DD%" & set "timestamp=%HH%%Min%%Sec%"
    set "fullstamp=%YYYY%-%MM%-%DD%_%HH%-%Min%-%Sec%"

    tracert www.google.com >"%fullstamp%.txt"

    goto :loop

    vkkhurava

      Topic Starter


      Starter

      • Experience: Beginner
      • OS: Windows 7
      Re: batch file for tracert
      « Reply #2 on: May 07, 2014, 09:24:52 AM »
      Thx for quick response...

      but please suggest where i have to put hours like 1, 2 or 3 after that this batch file auto execute and create different log file from the previous one.

      foxidrive



        Specialist
      • Thanked: 268
      • Experience: Experienced
      • OS: Windows 8
      Re: batch file for tracert
      « Reply #3 on: May 07, 2014, 10:15:03 AM »
      Explain what you need to do again.

      vkkhurava

        Topic Starter


        Starter

        • Experience: Beginner
        • OS: Windows 7
        Re: batch file for tracert
        « Reply #4 on: May 07, 2014, 09:21:20 PM »
        we want to create a batch file that -

        1. Should run automatically after 3 hours
        2. will run tracert & print out their results with date & time.
        3. when same batch run after 3 hour then it should create another file for that tracert report with date & time.

        I hope now I have explained it.

        Squashman



          Specialist
        • Thanked: 134
        • Experience: Experienced
        • OS: Other
        Re: batch file for tracert
        « Reply #5 on: May 08, 2014, 06:19:53 AM »
        Use Windows Scheduled Task to run the Batch file every 3 hours.

        vkkhurava

          Topic Starter


          Starter

          • Experience: Beginner
          • OS: Windows 7
          Re: batch file for tracert
          « Reply #6 on: May 08, 2014, 08:10:12 AM »
          Thanks guys... its really worked like a charm  :)

          rt-2



            Newbie

            • Experience: Expert
            • OS: Windows 7
            Re: batch file for tracert
            « Reply #7 on: November 29, 2016, 02:55:38 PM »
            Your question doesn't have all the details but see if this works for you:

            Code: [Select]
            @echo off
            :loop

            for /f "tokens=2 delims==" %%a in ('wmic OS Get localdatetime /value') do set "dt=%%a"
            set "YY=%dt:~2,2%" & set "YYYY=%dt:~0,4%" & set "MM=%dt:~4,2%" & set "DD=%dt:~6,2%"
            set "HH=%dt:~8,2%" & set "Min=%dt:~10,2%" & set "Sec=%dt:~12,2%"

            set "datestamp=%YYYY%%MM%%DD%" & set "timestamp=%HH%%Min%%Sec%"
            set "fullstamp=%YYYY%-%MM%-%DD%_%HH%-%Min%-%Sec%"

            tracert www.google.com >"%fullstamp%.txt"

            goto :loop
            I know its an old thread, but for me it didn't worked untill I did this:
            Code: [Select]
            @echo off
            cd A:\NY\Directories\You\Want\Your\results\In
            :loop

            for /f "tokens=2 delims==" %%a in ('wmic OS Get localdatetime /value') do set "dt=%%a"
            set "YY=%dt:~2,2%" & set "YYYY=%dt:~0,4%" & set "MM=%dt:~4,2%" & set "DD=%dt:~6,2%"
            set "HH=%dt:~8,2%" & set "Min=%dt:~10,2%" & set "Sec=%dt:~12,2%"

            set "datestamp=%YYYY%%MM%%DD%" & set "timestamp=%HH%%Min%%Sec%"
            set "fullstamp=%YYYY%-%MM%-%DD%_%HH%-%Min%-%Sec%"

            tracert www.google.com >"%fullstamp%.txt"

            goto :loop
            With the original code, it created about 3-4 empty files per seconds in the same directory.
            I am on Windows 7 64bit.