Skip to content

Instantly share code, notes, and snippets.

@eduardoaugustojulio
Last active September 16, 2019 13:02
Show Gist options
  • Save eduardoaugustojulio/a8014dbe210106b68c748447dba97440 to your computer and use it in GitHub Desktop.
Save eduardoaugustojulio/a8014dbe210106b68c748447dba97440 to your computer and use it in GitHub Desktop.
A script that pings simultaneously a list of ip addresses.
#!/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