Last active
February 29, 2024 22:00
-
-
Save foull/8595631f6856220fca04d288d721f694 to your computer and use it in GitHub Desktop.
ping_servers.sh
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 | |
# Ensure at least one server is provided | |
if [ "$#" -eq 0 ]; then | |
echo "Please provide at least one server as an argument." | |
exit 1 | |
fi | |
# Loop through all provided servers | |
for server in "$@" | |
do | |
# Ping the server, get the line with "avg" in it, then use awk to print the 4th field (avg ping) | |
ping_result=$(ping -c 10 "$server" | grep avg | awk -F '/' '{print $5}') | |
if [ -z "$ping_result" ]; then | |
echo "Could not retrieve ping for $server" | |
else | |
echo "[$server] [$ping_result ms]" | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment