summaryrefslogtreecommitdiff
path: root/bin
diff options
context:
space:
mode:
authormo <mo.khan@gmail.com>2019-05-25 19:22:26 -0600
committermo <mo.khan@gmail.com>2019-05-25 19:22:26 -0600
commit3f8ce1af3a6c6039e5eaecbf997f6939829f0c53 (patch)
tree22f329d90df5918df2bd48b50bff2b958578837b /bin
parent6864e92f727cb68d6b7c955fe4509a17bcaae13f (diff)
write a script to check if a host is on the network
Diffstat (limited to 'bin')
-rwxr-xr-xbin/problem-7.sh12
1 files changed, 12 insertions, 0 deletions
diff --git a/bin/problem-7.sh b/bin/problem-7.sh
new file mode 100755
index 0000000..1005ac3
--- /dev/null
+++ b/bin/problem-7.sh
@@ -0,0 +1,12 @@
+#!/bin/sh
+
+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