forked from AndyTaylorTweet/Pi-Star_Binaries_sbin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpistar-jittertest
executable file
·119 lines (113 loc) · 4.55 KB
/
pistar-jittertest
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
#!/bin/bash
#
###############################################################################
# #
# Pi-Star Jitter Tester #
# #
# Version 0.1, Code, Design and Development by Andy Taylor (MW0MWZ). #
# #
###############################################################################
#
if [ "$(id -u)" != "0" ]; then
echo -e "You need to be root to run this command...\n"
exit 1
fi
exec 200>/var/lock/pistar-jitter.lock || exit 1
if ! flock -n 200 ; then
echo -e "Another instance is already running...\n"
exit 1
fi
pingTest() {
hostp=${1}
# Clean up the Hostname
vanityName=$(tr -dc '[[:print:]]' <<< "${2}")
# Ping Test
pingTest=$(ping -W 2 -c 1 ${hostp} 2>/dev/null)
if [ $? -eq 0 ]; then
# if ping -W 2 -c 1 ${1} &> /dev/null; then
pingIP=$(echo ${pingTest} | awk '{print $3}')
if [ "(${hostp})" == "${pingIP}" ]; then pingIP=""; fi
pingResult=$(ping -W 2 -n -c 5 ${hostp} 2>/dev/null | grep "from" | tail -n 3 | awk -F 'time=' '{print $2}' | awk '{print $1}' | sort -g)
pingTestLow=$(echo ${pingResult} | awk '{print $1}')
pingTestMid=$(echo ${pingResult} | awk '{print $2}')
pingTestHigh=$(echo ${pingResult} | awk '{print $3}')
pingTestTotal=$(awk "BEGIN { printf \"%.2f\n\", ${pingTestHigh} + ${pingTestMid} + ${pingTestLow} }")
pingTestAvg=$(awk "BEGIN { printf \"%.2f\n\", ${pingTestTotal} / 3 } ")
pingTestPeakDev=$(awk "BEGIN { printf \"%.2f\n\", ${pingTestHigh} - ${pingTestLow} }")
echo ${vanityName},${hostp} ${pingIP},Avg RTT: ${pingTestAvg}ms,Peak Deviation: ${pingTestPeakDev}ms | awk -F"," '{printf "%-35s %-53s %-20s %-20.30s\n", $1, $2, $3, $4}'
else
echo ${vanityName},${hostp},unreachable...| awk -F"," '{printf "%-35s %-53s %-20s\n", $1, $2, $3}'
fi
}
main_function() {
case "${1}" in
NXDN)
while IFS="" read -r hostLine || [ -n "$p" ]
do
vanityName=$(echo ${hostLine} | awk '{print $2}')
host=$(echo ${hostLine} | awk '{print $2}')
pingTest ${host} ${vanityName} &
done < /usr/local/etc/NXDNHosts.txt
;;
P25)
while IFS="" read -r hostLine || [ -n "$p" ]
do
vanityName=$(echo ${hostLine} | awk '{print $2}')
host=$(echo ${hostLine} | awk '{print $2}')
pingTest ${host} ${vanityName} &
done < /usr/local/etc/P25Hosts.txt
;;
M17)
while IFS="" read -r hostLine || [ -n "$p" ]
do
if [[ ! "${hostLine:0:1}" == "#" ]]; then
vanityName=$(echo ${hostLine} | awk '{print $1}')
host=$(echo ${hostLine} | awk '{print $2}')
pingTest ${host} ${vanityName} &
fi
done < /usr/local/etc/M17Hosts.txt
;;
YSF)
while IFS="" read -r hostLine || [ -n "$p" ]
do
if [[ ! "${hostLine:0:1}" == "#" ]]; then
vanityName=$(echo ${hostLine} | awk -F";" '{print $2}')
host=$(echo ${hostLine} | awk -F";" '{print $4}')
pingTest ${host} ${vanityName} &
fi
done < /usr/local/etc/YSFHosts.txt
;;
*)
while IFS="" read -r hostLine || [ -n "$p" ]
do
if [[ ${hostLine} == ${1}_* ]]; then
vanityName=$(echo ${hostLine} | awk '{print $1}')
host=$(echo ${hostLine} | awk '{print $3}')
pingTest ${host} ${vanityName} &
fi
done < /usr/local/etc/DMR_Hosts.txt
;;
esac
}
if [ -z "$1" ]; then
thisScript="$(basename "$(test -L "$0" && readlink "$0" || echo "$0")")"
echo "This script ${thisScript} takes a single argument,"
echo "the prefix of the group of hosts you want to check"
echo "as used in the /usr/local/etc/DMR_Hosts.txt file."
echo ""
echo "For example: ${thisScript} BM"
echo "This will test against all hosts starting with BM"
exit 0
fi
if [ -t 1 ]; then
# run via terminal, only output to screen
main_function ${1}
wait
echo -e "\n-- End of tests"
else
# if not run via terminal, log everything into a log file
main_function ${1} >> /tmp/jittertest.log 2>&1
wait
echo -e "\n-- End of tests\n" | sudo tee -a /tmp/jittertest.log
fi
exit 0