-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathpingscript
48 lines (47 loc) · 1.29 KB
/
pingscript
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
39
40
41
42
43
44
45
46
47
#!/bin/bash
# originial script by @ubnt-stig from community.ubnt.com
# This is my attempt to optimize it.
# add your ping targets here
targets=(
'1.1.1.1'
'8.8.8.8'
'8.8.4.4'
)
# latency check (true|false)
latcheck=true
# Jitter check (true|false)
jitcheck=true
# If strictcheck=true then latency and jitter must be over max before failing
strictcheck=true
# add max latency/jitter here
maxlat=200
maxjit=20
[ $# != 3 ] && echo "Usages: $0 <group> <intf> <status>" exit 1
group=$1
intf=$2
status=$3
for host in "${targets[@]}"
do
pings () {
/bin/ping -n -c 4 -W 1 -w 1 -i 0.2 -I $2 $1 | tail -1 | awk -F '/' '{print $5 "-" $7}'
if [ ${PIPESTATUS[0]} -ne 0 ]; then
return 1
fi
}
if results=$(pings "$host" "$intf"); then
latency=$(echo $results | cut -f1 -d-)
jitter=$(echo $results | cut -f2 -d-)
striplat=$(echo ${latency%.*})
stripjit=$(echo ${jitter%.*})
[[ $latcheck = "true" && $jitcheck = "false" && $striplat -gt $maxlat ]] && break
[[ $latcheck = "false" && $jitcheck = "true" && $stripjit -gt $maxjit ]] && break
[[ $latcheck = "true" && $jitcheck = "true" && ($striplat -gt $maxlat || $stripjit -gt $maxjit) ]] && break
[[ $strictcheck = "true" && ($striplat -gt $maxlat && $stripjit -gt $maxjit) ]] && break
#end check latency/jitter
exit 0
else
break
fi
done
# fail
exit 1