Skip to content

Instantly share code, notes, and snippets.

@rewbs
Created September 18, 2024 04:34
Show Gist options
  • Save rewbs/6c789a77e576e14eeedd1cbeb0fddd2d to your computer and use it in GitHub Desktop.
Save rewbs/6c789a77e576e14eeedd1cbeb0fddd2d to your computer and use it in GitHub Desktop.
#!/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