Feb
22
Mass ping script
Filed Under Command line, Fix
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
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
$? – 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.