Last active
September 16, 2019 13:02
-
-
Save eduardoaugustojulio/a8014dbe210106b68c748447dba97440 to your computer and use it in GitHub Desktop.
A script that pings simultaneously a list of ip addresses.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
readonly ARGC=$# | |
readonly ARGV=( "$@" ) | |
readonly PROG_NAME=$(basename "$0") | |
usage() | |
{ | |
echo "Usage: $PROG_NAME <ip-list>" | |
exit 1 | |
} | |
ping_it() | |
{ | |
local address="$1" | |
local counts="1" | |
local time_out="1" | |
echo "$(ping -q -c "$counts" -W "$time_out" "$address")" | |
} | |
parallel_ping() | |
{ | |
local addresses="$1" | |
export -f ping_it | |
parallel ping_it :::: "$addresses" | |
} | |
main() | |
{ | |
if [ "$ARGC" -gt 0 ] | |
then | |
for file in $ARGV; | |
do | |
[[ -f "$file" ]] && parallel_ping "$file" | |
done | |
else | |
usage | |
fi | |
} | |
main |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment