-
Notifications
You must be signed in to change notification settings - Fork 41
/
pistar-jittertest
executable file
·82 lines (75 loc) · 2.83 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
#!/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() {
# Clean up the Hostname
vanityName=$(tr -dc '[[:print:]]' <<< "${2}")
if [ ${#vanityName} -le 23 ] && [ ${#vanityName} -gt 15 ]; then
vanityName="${vanityName}\t"
elif [ ${#vanityName} -le 15 ] && [ ${#vanityName} -gt 7 ]; then
vanityName="${vanityName}\t\t"
elif [ ${#vanityName} -le 7 ]; then
vanityName="${vanityName}\t\t\t"
else
vanityName="${vanityName::31}"
fi
# Ping Test
if ping -W 2 -c 1 ${1} &> /dev/null; then
pingResult=$(ping -W 2 -n -c 5 ${1} | 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} }")
printf "${vanityName}\tAvg RTT: ${pingTestAvg}ms\tPeak Deviation: ${pingTestPeakDev}ms\n"
else
printf "${vanityName}\tunreachable...\n"
fi
}
main_function() {
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
}
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
else
# if not run via terminal, log everything into a log file
main_function ${1} >> /var/log/pi-star/pi-star_icmptest.log 2>&1
wait
fi
exit 0