Skip to content

Commit

Permalink
minor upgrade in ping script
Browse files Browse the repository at this point in the history
  • Loading branch information
maldevel committed Oct 8, 2018
1 parent 32ebc3c commit ddf1a10
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions live-hosts/ping.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,20 +21,23 @@
#
# For more see the file 'LICENSE' for copying permission.

RED='\033[0;31m'
GREEN='\033[0;32m'
NC='\033[0m' # No Color
dd=$(date +"%Y-%m-%d-%H-%M")
logfile='icmp-live-hosts.txt'

if [ $# -eq 1 ]; then
logfile="icmp_live_hosts_$1"
logfile=$(echo "$logfile" | sed -r 's/[/]+/_/g' | sed -r 's/[.]+/_/g')
logfile="$logfile.txt"

file=$1
echo "---- $dd ----" >> $logfile
while IFS= read -r ipaddr
do
echo "Pinging $ipaddr.."
response=$(ping -c 1 -W 1 $ipaddr | grep 'bytes from' | cut -d' ' -f4 |sed 's/://')
if [ ! -z "$response" ]; then
printf "${RED}%s${NC} responds..\n" "$ipaddr"
printf "${GREEN}%s${NC} responds..\n" "$ipaddr"
echo "$ipaddr" >> $logfile
fi
done <"$file"
Expand Down

0 comments on commit ddf1a10

Please sign in to comment.