Options

Simple script to ping 8-10 servers?

tdeantdean Member Posts: 520
Anyone know how to write a simple batch file or something that will launch the cmd window and ping a bunch of servers so i dont have to do it individually?

Comments

  • Options
    docricedocrice Member Posts: 1,706 ■■■■■■■■■■
    for /f %%i in (machines.txt) do ping %%i

    This assumes you have a machine.txt file in the same directory as the batch script which has a list of hosts you want to ping, each on a different line.
    Hopefully-useful stuff I've written: http://kimiushida.com/bitsandpieces/articles/
  • Options
    RobertKaucherRobertKaucher Member Posts: 4,299 ■■■■■■■■■■
    tdean wrote: »
    Anyone know how to write a simple batch file or something that will launch the cmd window and ping a bunch of servers so i dont have to do it individually?

    What exactly are you trying to accomplish? Docrice's example is perfect but I have some more complex things you can use with PoSh but it deppends on why you are trying to ping them and what you want to do with the resulting information.
  • Options
    tdeantdean Member Posts: 520
    docrice wrote: »
    for /f %%i in (machines.txt) do ping %%i

    This assumes you have a machine.txt file in the same directory as the batch script which has a list of hosts you want to ping, each on a different line.
    Perfect!!! thanks. we have been having some pwr issues that have knocked out a few servers lately. i want to be able to click one thing to check them all.
  • Options
    instant000instant000 Member Posts: 1,745
    If you want to enhance that a little bit ...

    1. set it up to send the output somewhere > ping response.txt
    2. use a command line emailer to email the output (try blat)

    If you want to step up your game a bit ...

    1. get some decent monitoring software :D, no need to break the bank, and sourceforge would have to have some good ones. ... one that I've seen a provider use before is "nagios". "Zenoss" appears to have more downloads at sourceforge though.

    2. .... *ugh* just realized that I don't like this new sourceforge site layout ... it looks like they tried to make it "mobile-friendly" ... now I'm trying to search for how to get the old layout back.
    Currently Working: CCIE R&S
    LinkedIn: http://www.linkedin.com/in/lewislampkin (Please connect: Just say you're from TechExams.Net!)
  • Options
    DevilsbaneDevilsbane Member Posts: 4,214 ■■■■■■■■□□
    tdean wrote: »
    Perfect!!! thanks. we have been having some pwr issues that have knocked out a few servers lately. i want to be able to click one thing to check them all.

    If you aren't a fan of the loop thing, try this.
    @echo off
    ping server1 > output.txt
    ping server2 >> output.txt
    ping server3 >> output.txt
    
    and so on.

    The > will redirect the output to a file called output.txt. Notice that server 2 and beyond use >> which will append data to the output.txt file. If you only used > then when you opened the file it would only contain the last ping.

    You can also add switches in here too. -a switch to return the name of the computer (if you are pinging the ip) or the -n 1 switch if you only want 1 ping rather than the standard 4 are my personal favorites.
    Decide what to be and go be it.
  • Options
    ConstantlyLearningConstantlyLearning Member Posts: 445
    tdean wrote: »
    Perfect!!! thanks. we have been having some pwr issues that have knocked out a few servers lately. i want to be able to click one thing to check them all.

    Do you have a monitoring solution in place?

    You could set up Opsview or simalar.
    "There are 3 types of people in this world, those who can count and those who can't"
  • Options
    docricedocrice Member Posts: 1,706 ■■■■■■■■■■
    If you're planning to include an emailer (let's called it mailfoo.exe), we can expand the original statement above to:

    for /f %%i in (machines.txt) do ping %%i || emailfoo.exe admin@example.com -msg:"Host %%i is not responding"

    or something along those lines. As others have mentioned, a centralized monitoring solution is much better, but having a script like this is a cheap ghetto solution that works in a pinch.
    Hopefully-useful stuff I've written: http://kimiushida.com/bitsandpieces/articles/
Sign In or Register to comment.