Skip to content

Instantly share code, notes, and snippets.

@UKNC
Created April 12, 2017 09:14
Show Gist options
  • Save UKNC/a3b4641e19d1f93be005e4a9b96c0c0b to your computer and use it in GitHub Desktop.
Save UKNC/a3b4641e19d1f93be005e4a9b96c0c0b to your computer and use it in GitHub Desktop.
#!/bin/bash
hosts=(nqpc001 nqpc002 nqpc003 drft045 localhost "127.0.0.1")
for h in ${hosts[@]}; do
result=$(ping -c 2 -W 1 -q $h | grep transmitted)
pattern="0 received";
if [[ $result =~ $pattern ]]; then
echo "$h is down"
else
echo "$h is up"
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment