Created
July 28, 2021 06:29
-
-
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
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 | |
# 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