summaryrefslogtreecommitdiff
path: root/bin
diff options
context:
space:
mode:
authormo <mo.khan@gmail.com>2019-05-25 19:31:52 -0600
committermo <mo.khan@gmail.com>2019-05-25 19:31:52 -0600
commita0ed1fb8e76217c1013acff9169ba987c0c5044a (patch)
treeda5556a649468b6e922352847c678327579218a2 /bin
parent3b353f1d1f778798fa5a232fd29ef5dd1ce5b8f1 (diff)
check multiple hostnames at once
Diffstat (limited to 'bin')
-rwxr-xr-xbin/problem-7.sh25
1 files changed, 16 insertions, 9 deletions
diff --git a/bin/problem-7.sh b/bin/problem-7.sh
index 4e53180..8ec6e0c 100755
--- a/bin/problem-7.sh
+++ b/bin/problem-7.sh
@@ -5,13 +5,20 @@ if [ $# -eq 0 ]; then
exit 1
fi
-destination="$1"
-host=$(host "$1" | grep 'has address')
-ip=$(echo "$host" | cut -d' ' -f4)
-ping -c1 $ip > /dev/null 2>&1
+check() {
+ destination="$1"
+ host=$(host "$1" | grep 'has address')
+ ip=$(echo "$host" | cut -d' ' -f4)
+ ping -c1 $ip > /dev/null 2>&1
-if [ $? -eq 0 ]; then
- echo "$1" is on the network
-else
- echo "$1" is NOT on the network
-fi
+ if [ $? -eq 0 ]; then
+ echo "$1" is on the network
+ else
+ echo "$1" is NOT on the network
+ fi
+}
+
+for i in "$@"; do
+ check "$i"
+done
+exit 0