Created
September 18, 2024 04:34
-
-
Save rewbs/6c789a77e576e14eeedd1cbeb0fddd2d to your computer and use it in GitHub Desktop.
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 | |
# Check if at least one destination is provided | |
if [ $# -eq 0 ]; then | |
echo "Usage: $0 destination1 [destination2 ... destinationN]" | |
exit 1 | |
fi | |
# Function to ping a single destination | |
ping_destination() { | |
local DEST="$1" | |
echo "$(date '+%Y-%m-%d %H:%M:%S') - [$DEST] - Starting ping" | |
# Ping the destination indefinitely | |
ping "$DEST" | while IFS= read -r line; do | |
echo "$(date '+%Y-%m-%d %H:%M:%S') - [$DEST] - $line" | |
done | |
} | |
# Start pings in the background for each destination | |
for DEST in "$@"; do | |
ping_destination "$DEST" & | |
done | |
# Wait for all background processes (pings) | |
wait |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment