Skip to content

Instantly share code, notes, and snippets.

@rankun203
Last active August 29, 2015 14:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rankun203/e5e9ee0279b8ff3722f7 to your computer and use it in GitHub Desktop.
Save rankun203/e5e9ee0279b8ff3722f7 to your computer and use it in GitHub Desktop.
#!/bin/bash
#checkHosts.sh
#author rankun203@gmail.com
function success {
echo "isok $1 $2"
echo "$1 $2" >> ./hosts.ok
}
function fail {
echo "fail $1 $2"
}
function fping {
echo "ping $1 $2"
ping -c2 "$1" &>/dev/null && success $1 $2 || fail $1 $2
}
echo "" > ./hosts.ok
while IFS= read -r line; do
hasIp=$(echo "$line" | grep -Eo "^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\s+.*")
if [ "$hasIp" != "" ]
then
fping $(echo "$line" | grep -Eo "[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}") $(echo "$line" | grep -Eo "\ *[a-zA-Z_0-9\.]+$")
fi
done < "$1"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment