Skip to content

Instantly share code, notes, and snippets.

@wahengchang
Created July 28, 2021 06:29
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wahengchang/b30ee0b149cd830c565f2c2edb2d99af to your computer and use it in GitHub Desktop.
Save wahengchang/b30ee0b149cd830c565f2c2edb2d99af to your computer and use it in GitHub Desktop.
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