Created
February 3, 2016 12:29
-
-
Save imaizume/771d1bf6f2884ec3e351 to your computer and use it in GitHub Desktop.
Concurrently ping given IP and log the results with time stamp.
This file contains 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/bash | |
cd `dirname $0` | |
if [ $# -le 0 ]; then | |
echo "Please set more than 1 arguments" 1>&2 | |
exit 1 | |
fi | |
args=("$@") | |
argn=$# | |
timestamp=`date +'%Y-%m-%d_%H:%M:%S'` | |
network=192.168.1 | |
machine=$args | |
while true; do | |
for i in $(seq $argn); do | |
host=${network}.${args[$i-1]} | |
rslt=`ping -w 1 -c 1 -i 60 $host | grep 'bytes from '` | |
if [ $? -gt 0 ] | |
then echo -e "`date +'%Y-%m-%d %H:%M:%S'` $host Request timed out." >> $host/${timestamp}.log | |
else echo "`date +'%Y-%m-%d %H:%M:%S'` $host`echo $rslt | cut -d ':' -f 2`" >> $host/${timestamp}.log | |
fi | |
done | |
sleep 1m | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment