#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2012
    Posts
    3
    Rep Power
    0

    Help with a ping batch file please


    Hi,

    I have this problem at work.

    It looks like the connection to one of our servers is dropping out randomly.

    I want to write a batch file to constantly ping the server address and output the results to a text file that includes a date stamp. I also need to see the cmd prompt open and looking like its working for my peace of mind.

    I am on Windows Server 2000 and have tried the following:

    :TOP

    echo %time% >> C:\PingServer.txt

    ping serveraddress >> C:\PingServer.txt

    GOTO TOP

    I have tried testing this on my laptop at home but nothing happens. Im running Windows 7 at home.

    Thanks in advance
  2. #2
  3. Automagically Delicious
    Devshed Regular (2000 - 2499 posts)

    Join Date
    May 2004
    Location
    127.0.0.2 - I live next door.
    Posts
    2,202
    Rep Power
    2737
    Code:
    ping -t 192.168.1.1 << C:\pingout.txt
    This might not display to the screen but your text file will continue to fill. You can run the above without running it as a script.
    Adam TT
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2012
    Posts
    3
    Rep Power
    0
    Originally Posted by AdamPI
    Code:
    ping -t 192.168.1.1 << C:\pingout.txt
    This might not display to the screen but your text file will continue to fill. You can run the above without running it as a script.
    The file don't write on my machine. How do you write this in dos?

    Thanks
  6. #4
  7. Providing fuel for space ships
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2004
    Location
    nr Edinburgh, Scotland
    Posts
    14,382
    Rep Power
    3848
    This is in DOS, only the chevrons are the wrong way around:
    Code:
    ping -t 192.168.1.1 >> C:\pingout.txt
    The No Ma'am commandments:

    1.) It is O.K. to call hooters 'knockers' and sometimes snack trays
    2.) It is wrong to be French
    3.) It is O.K. to put all bad people in a giant meat grinder
    4.) Lawyers, see rule 3
    5.) It is O.K. to drive a gas guzzler if it helps you get babes
    6.) Everyone should car pool but me
    7.) Bring back the word 'stewardesses'
    8.) Synchronized swimming is not a sport
    9.) Mud wrestling is a sport
  8. #5
  9. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2012
    Posts
    3
    Rep Power
    0
    Thanks for that. Sorry I missed it before as I was looking on my phone. Could you please tell me how to add a time stamp to each sent ping?
  10. #6
  11. Automagically Delicious
    Devshed Regular (2000 - 2499 posts)

    Join Date
    May 2004
    Location
    127.0.0.2 - I live next door.
    Posts
    2,202
    Rep Power
    2737
    In that case you will need a script (Sorry about the backwards brackets.)

    I'd suggest using Powershell, your script could look something like this:
    Code:
    $logs = "C:\pingDS.txt"
    $wait = 10
    
    while("true"){
        Get-Date | out-file "$logs" -append
        ping 127.0.0.1 | out-file "$logs" -append
        
        "Waiting $wait seconds"
        start-sleep -s $wait
    }
    wrote it quick and dirty, so it may need some polishing
    Adam TT
  12. #7
  13. No Profile Picture
    Grumpier old Moderator
    Devshed Supreme Being (6500+ posts)

    Join Date
    Jun 2003
    Posts
    14,441
    Rep Power
    4539
    Just FYI there are a bunch of available server monitoring applications both free and non-free. One of these apps may be better for you. Most include email notifications and such.
    ======
    Doug G
    ======
    Bartender to Rene Descartes "have another beer?" Descartes: "I think not" and he vanished.
    --Alfred Bester

IMN logo majestic logo threadwatch logo seochat tools logo