From fef00b2652de0df0627d1a814e4be6aa4e8f9504 Mon Sep 17 00:00:00 2001 From: Jensfrank Date: Fri, 28 Jun 2024 21:26:13 +0800 Subject: [PATCH] Update nodeloc_vps_autotest_speed.sh --- nodeloc_vps_autotest_speed.sh | 57 ++++++++++++----------------------- 1 file changed, 19 insertions(+), 38 deletions(-) diff --git a/nodeloc_vps_autotest_speed.sh b/nodeloc_vps_autotest_speed.sh index 7b4fdb6..7dc0815 100644 --- a/nodeloc_vps_autotest_speed.sh +++ b/nodeloc_vps_autotest_speed.sh @@ -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=\"多线程测速\"]