Last active
March 21, 2018 00:57
-
-
Save ericwastaken/2e6105d3bd9806853b61b3f16d57abcc to your computer and use it in GitHub Desktop.
Given a file path that has a hostname per line, uses another script to get the IP for each host then tries an ICMP ping and returns those that reply
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# ********************************************************************* | |
# script: filetopingreply | |
# summary: given a file path (assuming it has a host per line), uses | |
# another script to get the IP for each host then tries | |
# an ICMP ping and returns those that reply | |
# NOTE: Backgrounds each PING to perform these faster! | |
# dependencies: filetoiplist (in same path as this script); grep | |
# by: e.a.soto, [email protected] | |
# | |
# history | |
# ======= | |
# | |
# 2015-09-16: created. | |
# | |
# ********************************************************************* | |
# path to where this script stored (we assume dependent scripts are here too) | |
BASEDIR=$(dirname $0) | |
# check for required parameter | |
if [ $# -eq 0 ] | |
then | |
echo "File Path must be supplied!" | |
exit 1 | |
fi | |
# basic logic | |
# | |
# use for to loop through each line in the output of filetoiplist | |
# does "ping" command on each | |
# pipes to grep looking for reply "bytes from" | |
# pipes to cut to get rid of extraneous characters | |
for ip in $($BASEDIR/filetoiplist.sh "$1") | |
do ping -c1 $ip | | |
grep "bytes from" | | |
cut -d" " -f4 | | |
cut -d":" -f1 & | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment