forked from 91yun/91yuntest
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.sh
108 lines (83 loc) · 2.24 KB
/
test.sh
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
#!/bin/bash
PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin
export PATH
Color_Text()
{
echo -e " \e[0;$2m$1\e[0m"
}
Echo_Red()
{
echo $(Color_Text "$1" "31")
}
Echo_Green()
{
echo $(Color_Text "$1" "32")
}
Echo_Yellow()
{
echo -n $(Color_Text "$1" "33")
}
Echo_Blue()
{
echo $(Color_Text "$1" "34")
}
next() {
printf "%-70s\n" "-" | sed 's/\s/-/g'
}
echo "服务器提供商(host provider)[default:Enter]"
read hostp
echo "开始测试中,会需要点时间,请稍后"
_included_benchmarks=""
#取参数
while getopts "i:" opt; do
case $opt in
i) _included_benchmarks=$OPTARG;;
esac
done
#默认参数
if [ "$_included_benchmarks" == "" ]; then
_included_benchmarks="io,bandwidth,download,traceroute,backtraceroute,allping"
fi
_included_benchmarks="systeminfo,"${_included_benchmarks}
#预先安装库,如果有进行benchtest就会多安装些东西
bt="benchtest"
if [[ $_included_benchmarks == *$bt* ]]
then
apt-get >/dev/null 2>&1
[ $? -le '1' ] && ( apt-get update | apt-get -y install curl mtr virt-what python perl automake autoconf time make gcc gdb )
yum >/dev/null 2>&1
[ $? -le '1' ] && yum -y install which sed curl mtr virt-what python make gcc gcc-c++ gdbautomake autoconf time perl-Time-HiRes perl
else
apt-get >/dev/null 2>&1
[ $? -le '1' ] && ( apt-get update | apt-get -y install curl mtr virt-what python )
yum >/dev/null 2>&1
[ $? -le '1' ] && yum -y install which sed curl mtr virt-what python
fi
#要用到的变量
backtime=`date +%Y%m%d`
logfilename="test91yun.log"
dir=`pwd`
IP=$(curl -s myip.ipip.net | awk -F ' ' '{print $2}' | awk -F ':' '{print $2}')
echo "====开始记录测试信息====">${dir}/$logfilename
#创建测试目录
mkdir -p 91yuntest
cd 91yuntest
clear
#取得测试的参数值
arr=(${_included_benchmarks//,/ })
#下载执行相应的代码
for i in ${arr[@]}
do
wget -q --no-check-certificate https://raw.githubusercontent.com/91yun/91yuntest/test/test_code/${i}.sh
. ${dir}/91yuntest/${i}.sh
eval ${i}
done
#上传文件
updatefile()
{
resultstr=$(curl -s -T ${dir}/$logfilename "https://test.91yun.org/logfileupload.php")
echo -e $resultstr | tee -a ${dir}/$logfilename
}
updatefile
#删除目录
rm -rf ${dir}/91yuntest