-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathping.sh
More file actions
executable file
·38 lines (36 loc) · 782 Bytes
/
ping.sh
File metadata and controls
executable file
·38 lines (36 loc) · 782 Bytes
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
32
33
34
35
36
37
38
#!/bin/bash
# First argument is the host to ping
# Second argument is the RRD-file to update
PING=/bin/ping
COUNT=4
DEADLINE=30
ping_host() {
local output=$($PING -q -n -c $COUNT -w $DEADLINE $1 2>&1)
# notice $output is quoted to preserve newlines
local temp=$(echo "$output"| gawk '
BEGIN {pl=100; rtt=0.1}
/packets transmitted/ {
match($0, /([0-9]+)% packet loss/, matchstr)
pl=matchstr[1]
}
/^rtt/ {
# looking for something like 0.562/0.566/0.571/0.024
match($4, /(.*)\/(.*)\/(.*)\/(.*)/, a)
rtt=a[2]
}
/unknown host/ {
# no output at all means network is probably down
pl=100
rtt=0.1
}
END {print pl ":" rtt}
')
RETURN_VALUE=$temp
}
# ping a host on the local lan
ping_host $1
/usr/bin/rrdtool update \
$2 \
--template \
pl:rtt \
N:$RETURN_VALUE