You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
37 lines
1.1 KiB
Bash
37 lines
1.1 KiB
Bash
#!/bin/bash
|
|
|
|
# Usage: doPingTest <target-host> [<count>]
|
|
function doPingTest {
|
|
HOST=${1}
|
|
|
|
logScript "Doing ping to ${HOST}"
|
|
|
|
COUNT=1
|
|
[ "${2}" = "" ] || COUNT=${2}
|
|
|
|
ping "${HOST}" -W 10 -c ${COUNT} | {
|
|
read -r HEADER
|
|
RESOLVED_NAME=$(echo ${HEADER} | sed 's/.* (\(.*\)) .*/\1/')
|
|
|
|
while read -r PINGLINE; do
|
|
if [[ "${PINGLINE}" == *" bytes from "* ]]; then
|
|
SUCCESS=true
|
|
BYTES=$(echo ${PINGLINE} | awk '{ print $1 }')
|
|
TTL=$(echo ${PINGLINE} | sed 's/.*ttl=\([0-9]\+\) .*/\1/')
|
|
LATENCY=$(echo ${PINGLINE} | sed 's/.*time=\([0-9\.]\+\) .*/\1/')
|
|
elif [ "${PINGLINE}" = "" ]; then
|
|
SUCCESS=false
|
|
BYTES=0
|
|
TTL=0
|
|
LATENCY=-1
|
|
else
|
|
continue
|
|
fi
|
|
|
|
writeData \
|
|
ping \
|
|
"sourceHost=$(hostname -f),targetHost=${HOST}" \
|
|
"success=${SUCCESS},resolved=\"${RESOLVED_NAME}\",latency=${LATENCY},ttl=${TTL},bytes=${BYTES}"
|
|
done
|
|
}
|
|
} |