-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathping_stat.sh
More file actions
executable file
·87 lines (71 loc) · 2.36 KB
/
ping_stat.sh
File metadata and controls
executable file
·87 lines (71 loc) · 2.36 KB
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
#!/bin/bash
#---------------------------------------------------------------#
# ScriptsName: ping_stat.sh #
# ScriptsPath:/root/scripts/ping_stat.sh #
# Purpose: test new node ping all node statistcs #
# Edition: 1.0 #
# CreateDate:2016-08-23 15:31 #
# Author: Payne Zheng <zzuai520@live.com> #
#---------------------------------------------------------------#
Help() {
echo "Usage: $(basename $0) iplist packets-num yousort(avg|min|max|loss)"
exit
}
inited() {
rpm -qa|grep rsync || yum install rsync -y &> /dev/null
}
upload() {
local server ip file
server="114.119.10.168"
ip=$(ifconfig | grep "inet addr" | grep -v 127.0.0.1 | awk '{print $2}' | tr -d "addr:" | head -1)
file=$1
rsync -av --contimeout=20 --timeout=20 $file $server::ping_log/$ip/
}
test $# -ne 3 && Help
#inited
iplist=$1
packets=$2
typeset -u yousort=$3
tempfile=$(mktemp)
log_dir=/root/pingstat
test -d ${log_dir} || mkdir ${log_dir}
log_file=${log_dir}/ping_$(date +%m%d%H%M).log
cat ${iplist} | xargs -P 50 -L 1 ping -c "$packets" | grep -A2 "ping statistics" > ${log_file}
sed -i -r 's/^--$//g' ${log_file}
sed -i -r 's/^--- //g' ${log_file}
sed -i -r 's/ ping statistics ---$/,/g' ${log_file}
cat ${log_file} | tr ' |/' ',' > ${tempfile}
sed -i -r 's/^[0-9]+,packets.*received,,//g' ${tempfile}
sed -i -r 's/,time,[0-9]*ms$//g' ${tempfile}
awk -vRS='' 'NF+=0' OFS='' ${tempfile} > ${log_file}
awk -F, '{print $1,"LOSS: "$2,"MIN: "$11,"MAX: "$13,"AVG: "$12}' ${log_file} | column -t > ${tempfile}
case $yousort in
"AVG")
sort -nk9 ${tempfile} > ${log_file}
;;
"MIN")
sort -nk5 ${tempfile} > ${log_file}
;;
"MAX")
sort -nk7 ${tempfile} > ${log_file}
;;
"LOSS")
sort -nk3 ${tempfile} > ${log_file}
;;
*)
sort -nk9 ${tempfile} > ${log_file}
;;
esac
GREEN_COLOR='\E[1;32m'
RES='\E[0m'
echo -e "\a"
echo -e "${GREEN_COLOR}========== +++ TEST FINISHED +++ ==========${RES}"
echo -e "${GREEN_COLOR}== TO SEE LOG FILE : ${log_file} ==${RES}"
echo
#upload ${log_file}
#if [ $? -eq 0 ]; then
# echo "${log_file} uploaded ok" >> /tmp/pingstat.log
#else
# echo "${log_file} uploaded failed" >> /tmp/pingstat.log
#fi
rm -f ${tempfile}