Update nodeloc_vps_autotest_speed.sh

This commit is contained in:
Jensfrank 2024-06-28 21:26:13 +08:00 committed by GitHub
parent 310de3e271
commit fef00b2652
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -109,20 +109,21 @@ run_and_capture() {
echo "$command_output"
}
# 去除三网测速板块ANSI转义码并截取(多线程)
speedtest_multi_process_output() {
# 去除三网测速板块ANSI转义码并截取
process_speedtest_output() {
local input="$1"
# Step 1: 去除 ANSI 转义码
local keyword="$2"
# 去除 ANSI 转义码
local no_ansi
no_ansi=$(echo "$input" | sed -E 's/\x1b\[[0-9;]*[a-zA-Z]//g')
# Step 2: 计算关键字出现的次数
# 计算关键字出现的次数
local count
count=$(echo "$no_ansi" | grep -Fc "大陆三网+教育网 IPv4 多线程测速")
count=$(echo "$no_ansi" | grep -Fc "$keyword")
# Step 3: 提取所需的测试结果并过滤进度条
local speedtest_multi_process_output_result
speedtest_multi_process_output_result=$(echo "$no_ansi" | awk -v count="$count" -v key="大陆三网+教育网 IPv4 多线程测速" '
# 提取所需的测试结果并过滤进度条
echo "$no_ansi" | awk -v count="$count" -v key="$keyword" '
$0 == key {
if (--count == 0) {
f=1; next
@ -130,35 +131,17 @@ speedtest_multi_process_output() {
}
f && !/测试进行中/ && NF;
/系统时间:/ {exit}
')
echo "$speedtest_multi_process_output_result"
'
}
# 去除三网测速板块ANSI转义码并截取单线程
# 提取三网测速板块(多线程)
speedtest_multi_process_output() {
process_speedtest_output "$1" "大陆三网+教育网 IPv4 多线程测速"
}
# 提取三网测速板块(单线程)
speedtest_single_process_output() {
local input="$1"
# Step 1: 去除 ANSI 转义码
local no_ansi
no_ansi=$(echo "$input" | sed -E 's/\x1b\[[0-9;]*[a-zA-Z]//g')
# Step 2: 计算关键字出现的次数
local count
count=$(echo "$no_ansi" | grep -Fc "大陆三网+教育网 IPv4 单线程测速")
# Step 3: 提取所需的测试结果并过滤进度条
local speedtest_single_process_output_result
speedtest_single_process_output_result=$(echo "$no_ansi" | awk -v count="$count" -v key="大陆三网+教育网 IPv4 单线程测速" '
$0 == key {
if (--count == 0) {
f=1; next
}
}
f && !/测试进行中/ && NF;
/系统时间:/ {exit}
')
echo "$speedtest_single_process_output_result"
process_speedtest_output "$1" "大陆三网+教育网 IPv4 单线程测速"
}
# 运行所有测试
@ -180,10 +163,8 @@ run_all_tests() {
format_results() {
# 处理三网测速结果
local processed_speedtest_multi_result
local processed_speedtest_single_result
processed_speedtest_multi_result=$(speedtest_multi_process_output "$speedtest_multi_result")
processed_speedtest_single_result=$(speedtest_single_process_output "$speedtest_single_result")
local processed_speedtest_multi_result=$(speedtest_multi_process_output "$speedtest_multi_result")
local processed_speedtest_single_result=$(speedtest_single_process_output "$speedtest_single_result")
result="[tabs]
[tab=\"多线程测速\"]