Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
ping multiple IP's using bash, Loop through an array of strings of IP. and save the result to text file, with naming
#!/bin/bash
# Program name: pingLoop.sh
# Run: source pingLoop.sh
# put your target list of ip to arr
declare -a arr=("192.168.0.1" "192.168.0.2")
for ip in "${arr[@]}"
do
# change 200 to the number of packets that you want
ping -c 200 "$ip" > ./$ip
if [ $? -eq 0 ]; then
echo "node $ip is up"
else
echo "node $ip is down"
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment