Skip to content

Instantly share code, notes, and snippets.

@viniroger
Last active June 5, 2018 20:10
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 viniroger/f93e53f766e1c7eba44bdabfbf45d898 to your computer and use it in GitHub Desktop.
Save viniroger/f93e53f766e1c7eba44bdabfbf45d898 to your computer and use it in GitHub Desktop.
Test many IP addresses and save output on log file
#!/bin/bash
# Script to test many IP addresses
ips=( '192.168.0.1' '192.168.0.2' '192.168.0.4' '192.168.0.12' '192.168.0.102' )
descr=( 'Host 1' 'Host 2' 'Host 3' 'Host 4' 'Host 5' )
filename='pings_'$(cat /etc/hostname)'.txt'
rm -f $filename; touch $filename
n=0
for ip in "${ips[@]}"; do
echo "=====" $ip ${descr[$n]} "=====" >> $filename
ping $ip -c 5 | grep packet >> $filename
printf "\n" >> $filename
n=$((n+1))
#exit
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment