-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathping.sh
executable file
·31 lines (24 loc) · 921 Bytes
/
ping.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#/bin/bash
METRIC=$1
DEST=$2
SOURCE=$3
COUNT=2
PING_COMMAND=$(ping -c "$COUNT" "$DEST" -I "$SOURCE")
if [ "$METRIC" == "packet_loss" ]; then
PACKET_LOSS_PING=$(echo -e "$PING_COMMAND" | grep "packet loss" | cut -d " " -f 6)
echo "$PACKET_LOSS_PING"
elif [ "$METRIC" == "latency_min" ]; then
LATENCY_MIN=$(echo -e "$PING_COMMAND" | grep "rtt" | cut -d "/" -f 4 | cut -d "=" -f 2 | cut -d " " -f 2)
echo "$LATENCY_MIN"
elif [ "$METRIC" == "latency_avg" ]; then
LATENCY_AVG=$(echo -e "$PING_COMMAND" | grep "rtt" | cut -d "/" -f 5 | cut -d " " -f 1)
echo "$LATENCY_AVG"
elif [ "$METRIC" == "latency_max" ]; then
LATENCY_MAX=$(echo -e "$PING_COMMAND" | grep "rtt" | cut -d "/" -f 6)
echo "$LATENCY_MAX"
elif [ "$METRIC" == "latency_mdev" ]; then
LATENCY_MDEV=$(echo -e "$PING_COMMAND" | grep "rtt" | cut -d "/" -f 7)
echo "$LATENCY_MDEV"
else
echo "Wrong metric argument"
fi