ML
    • Recent
    • Categories
    • Tags
    • Popular
    • Users
    • Groups
    • Register
    • Login

    Making a Simple Ping Test Script

    IT Discussion
    bash ping script scripting shell
    1
    1
    1.2k
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • S
      scottalanmiller
      last edited by

      Sometimes we just want a simple tool to test ping or similar functions. Don't need anything fancy. So let's do a little BASHing and make a simple script to meet this need. For our example we will make a little ping script that will take a text file as input and ping the hosts and deliver an up or down status on them.

      First we should make a little text file to start testing with. Just open up your editor and put in some IP addresses:

       vi pinglist
      

      For testing I just used 8.8.8.8 and 8.8.4.4 but you should fill in machines that you care about here. Make sure to put each entry on its own line. You can use IP addresses or Hostnames, but be aware that if you use hostname that you are testing DNS resolution and PING at the same time and if either fails you will get a bad result, so this may or may not make sense for you.

      Now for our script...

      #!/bin/bash
      
      for i in $(cat pinglist); do
          echo $i $(if ping -q -c 1 $i > /dev/null ; then echo up; else echo down; fi)
      done
      

      Save this file as pinger. Then mark it for execution with chmod +x pinger. Done. Works very simply.

      1 Reply Last reply Reply Quote 3
      • 1 / 1
      • First post
        Last post