I needed to check multiple addresses for use.

I did not find any ready solution so I wrote a script.

I called it psweep.sh

Here is it(comments are welcomed):

#!/bin/bash
# Sweep ping
# 1-st arg ip 2-nd start 3-d end
#
# Written by Hristo Benev
#
# rev 0.3
#
for i in `seq $2 $3`; do
ping -c 1 -W 1 $1.$i >/dev/null 2>&1
#ping -c 1 -W 1 $1.$i
if [ $? == 0 ]; then
echo "host $1.$i is up"
else
echo "."
fi
done
# changelog
# 0.3 added progress

Comments

2 Responses to “Mass ping script”

  1. JT on October 12th, 2010 10:49 pm

    Can you please explain the below commands.

    I am wondering how the if clause knows when to display when the host is up.
    What is the variable $?

    ping -c 1 -W 1 $1.$i >/dev/null 2>&1
    if [ $? == 0 ]; then

    Thanks

  2. hb on October 13th, 2010 5:48 am

    $? – returns the result of execution of the last command (return value)…

    If you need additional information about bash scrips check one of the Bash tutorials available on the Net.

Leave a Reply

You must be logged in to post a comment.