Skip to content

Instantly share code, notes, and snippets.

@imaizume
Created February 3, 2016 12:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save imaizume/771d1bf6f2884ec3e351 to your computer and use it in GitHub Desktop.
Save imaizume/771d1bf6f2884ec3e351 to your computer and use it in GitHub Desktop.
Concurrently ping given IP and log the results with time stamp.
#!/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