Created
April 5, 2021 12:02
-
-
Save tomwassenberg/2026e0999c9ee0cc951d2a8e11f04bc3 to your computer and use it in GitHub Desktop.
A script that pings a host and for any timeouts, prints the ICMP sequence number and date
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
#!/usr/bin/env bash | |
# Ping a host and for any timeouts, print the ICMP sequence number and date | |
set -eEfuo pipefail | |
IFS=$'\n' | |
declare -i ICMP_SEQ ICMP_TIMEOUT_IN_SECONDS=1 | |
TARGET_IP=${1} | |
shift | |
ping "${TARGET_IP}" -D -n -O -W "${ICMP_TIMEOUT_IN_SECONDS}" | | |
{ | |
# Strip ping header | |
read -r | |
while read -r ICMP_REQUEST; do | |
[[ ${ICMP_REQUEST} =~ ^\[([[:digit:].]+)\].*icmp_seq=([[:digit:]]+) ]] | |
ICMP_TIMESTAMP=${BASH_REMATCH[1]} | |
ICMP_SEQ=${BASH_REMATCH[2]} | |
if [[ ! ${ICMP_REQUEST} =~ \ | |
"bytes from ${TARGET_IP}: icmp_seq="("${ICMP_SEQ}") ]]; then | |
echo \ | |
"Missed ICMP request ${ICMP_SEQ} at $(date -d @"${ICMP_TIMESTAMP}")!" | |
fi | |
done | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment