获取hub信息
假如我们想要获取linux上hub固定插口的设备序列号,可以用到usb-devices工具获取,
信息过滤
#!/bin/bash
rm -rf ~/test/resource/gms_common_function/SerialNum/*
usb-devices >~/test/resource/gms_common_function/SerialNum/SerialNum_info.txt
hub1_1=$(cat ~/test/resource/gms_common_function/USB_HUB_PORT.txt |grep "hub1_1:"|sed "s/hub1_1://g")
hub1_2=$(cat ~/test/resource/gms_common_function/USB_HUB_PORT.txt |grep "hub1_2:"|sed "s/hub1_2://g")
cat ~/test/resource/gms_common_function/SerialNum/SerialNum_info.txt \
|grep -E "^T|^S: SerialNumber="|sed -n "/$hub1_1/,/$hub1_2/p" \
>~/test/resource/gms_common_function/SerialNum/hub1_SerialNum_info.txt
hub2_1=$(cat ~/test/resource/gms_common_function/USB_HUB_PORT.txt |grep "hub2_1:"|sed "s/hub2_1://g")
hub2_2=$(cat ~/test/resource/gms_common_function/USB_HUB_PORT.txt |grep "hub2_2:"|sed "s/hub2_2://g")
cat ~/test/resource/gms_common_function/SerialNum/SerialNum_info.txt \
|grep -E "^T|^S: SerialNumber="|sed -n "/$hub2_1/,/$hub2_2/p" \
>~/test/resource/gms_common_function/SerialNum/hub2_SerialNum_info.txt
hub3_1=$(cat ~/test/resource/gms_common_function/USB_HUB_PORT.txt |grep "hub3_1:"|sed "s/hub3_1://g")
hub3_2=$(cat ~/test/resource/gms_common_function/USB_HUB_PORT.txt |grep "hub3_2:"|sed "s/hub3_2://g")
cat ~/test/resource/gms_common_function/SerialNum/SerialNum_info.txt \
|grep -E "^T|^S: SerialNumber="|sed -n "/$hub3_1/,/$hub3_2/p" \
>~/test/resource/gms_common_function/SerialNum/hub3_SerialNum_info.txt
hub4_1=$(cat ~/test/resource/gms_common_function/USB_HUB_PORT.txt |grep "hub4_1:"|sed "s/hub4_1://g")
hub4_2=$(cat ~/test/resource/gms_common_function/USB_HUB_PORT.txt |grep "hub4_2:"|sed "s/hub4_2://g")
cat ~/test/resource/gms_common_function/SerialNum/SerialNum_info.txt \
|grep -E "^T|^S: SerialNumber="|sed -n "/$hub4_1/,/$hub4_2/p" \
>~/test/resource/gms_common_function/SerialNum/hub4_SerialNum_info.txt
cts_num=$(cat ~/test/resource/gms_common_function/USB_HUB_PORT.txt |grep "cts[0-9][0-9]*"|wc -l)
echo "cts port number is $cts_num"
for ((integer=1;integer<=${cts_num};integer++))
do
port=$(cat ~/test/resource/gms_common_function/USB_HUB_PORT.txt |grep "cts[0-9][0-9]*" |sed -n "${integer}p" |sed 's/^.*cts[0-9][0-9]*://g')
cat ~/test/resource/gms_common_function/SerialNum/hub3_SerialNum_info.txt |grep -A 5 "${port}"| sed -n "2p"| sed "s/^.*SerialNumber=//g"\
|cut -d " " -f1>>~/test/resource/gms_common_function/SerialNum/CTS_serial.txt
done
gts_num=$(cat ~/test/resource/gms_common_function/USB_HUB_PORT.txt |grep "gts[0-9][0-9]*"|wc -l)
echo "gts port number is $gts_num"
for ((integer=1;integer<=${gts_num};integer++))
do
port=$(cat ~/test/resource/gms_common_function/USB_HUB_PORT.txt |grep "gts[0-9][0-9]*" |sed -n "${integer}p" |sed 's/^.*gts[0-9][0-9]*://g')
cat ~/test/resource/gms_common_function/SerialNum/hub4_SerialNum_info.txt |grep -A 5 "${port}"| sed -n "2p"| sed "s/^.*SerialNumber=//g"\
|cut -d " " -f1>>~/test/resource/gms_common_function/SerialNum/GTS_serial.txt
done
vts_num=$(cat ~/test/resource/gms_common_function/USB_HUB_PORT.txt |grep "vts[0-9][0-9]*"|wc -l)
echo "vts port number is $vts_num"
for ((integer=1;integer<=${vts_num};integer++))
do
port=$(cat ~/test/resource/gms_common_function/USB_HUB_PORT.txt |grep "vts[0-9][0-9]*" |sed -n "${integer}p" |sed 's/^.*vts[0-9][0-9]*://g')
cat ~/test/resource/gms_common_function/SerialNum/hub4_SerialNum_info.txt |grep -A 5 "${port}"| sed -n "2p"| sed "s/^.*SerialNumber=//g"\
|cut -d " " -f1>>~/test/resource/gms_common_function/SerialNum/VTS_serial.txt
done
sts_num=$(cat ~/test/resource/gms_common_function/USB_HUB_PORT.txt |grep "sts[0-9][0-9]*"|wc -l)
echo "sts port number is $sts_num"
for ((integer=1;integer<=${sts_num};integer++))
do
port=$(cat ~/test/resource/gms_common_function/USB_HUB_PORT.txt |grep "sts[0-9][0-9]*" |sed -n "${integer}p" |sed 's/^.*sts[0-9][0-9]*://g')
cat ~/test/resource/gms_common_function/SerialNum/hub4_SerialNum_info.txt |grep -A 5 "${port}"| sed -n "2p"| sed "s/^.*SerialNumber=//g"\
|cut -d " " -f1>>~/test/resource/gms_common_function/SerialNum/STS_serial.txt
done
cts_instant_num=$(cat ~/test/resource/gms_common_function/USB_HUB_PORT.txt |grep "cts_instant[0-9][0-9]*"|wc -l)
echo "cts_instant port number is $cts_instant_num"
for ((integer=1;integer<=${cts_instant_num};integer++))
do
port=$(cat ~/test/resource/gms_common_function/USB_HUB_PORT.txt |grep "cts_instant[0-9][0-9]*" |sed -n "${integer}p" |sed 's/^.*cts_instant[0-9][0-9]*://g')
cat ~/test/resource/gms_common_function/SerialNum/hub4_SerialNum_info.txt |grep -A 5 "${port}"| sed -n "2p"| sed "s/^.*SerialNumber=//g"\
|cut -d " " -f1>>~/test/resource/gms_common_function/SerialNum/cts_instant_serial.txt
done
cts_on_gsi_num=$(cat ~/test/resource/gms_common_function/USB_HUB_PORT.txt |grep "cts_on_gsi[0-9][0-9]*"|wc -l)
echo "cts_on_gsi port number is $cts_on_gsi_num"
for ((integer=1;integer<=${cts_on_gsi_num};integer++))
do
port=$(cat ~/test/resource/gms_common_function/USB_HUB_PORT.txt |grep "cts_on_gsi[0-9][0-9]*" |sed -n "${integer}p" |sed 's/^.*cts_on_gsi[0-9][0-9]*://g')
cat ~/test/resource/gms_common_function/SerialNum/hub2_SerialNum_info.txt |grep -A 5 "${port}"| sed -n "2p"| sed "s/^.*SerialNumber=//g"\
|cut -d " " -f1>>~/test/resource/gms_common_function/SerialNum/cts_on_gsi_serial.txt
done
perf_num=$(cat ~/test/resource/gms_common_function/USB_HUB_PORT.txt |grep "perf[0-9][0-9]*"|wc -l)
echo "perf port number is $perf_num"
for ((integer=1;integer<=${perf_num};integer++))
do
port=$(cat ~/test/resource/gms_common_function/USB_HUB_PORT.txt |grep "perf[0-9][0-9]*" |sed -n "${integer}p" |sed 's/^.*perf[0-9][0-9]*://g')
cat ~/test/resource/gms_common_function/SerialNum/hub1_SerialNum_info.txt |grep -A 5 "${port}"| sed -n "2p"| sed "s/^.*SerialNumber=//g"\
|cut -d " " -f1>>~/test/resource/gms_common_function/SerialNum/performance_serial.txt
done
# for test_type in {"cts","gts","sts","vts","cts_instant","cts_on_gsi"}
# do
# test_type_num="${test_type}_num"
# test_type_num=$(cat ~/test/resource/gms_common_function/USB_HUB_PORT.txt |grep "${test_type}[0-9][0-9]*"|wc -l)
# echo $test_type_num
# for ((integer=1;integer<=${test_type_num};integer++))
# do
# echo "~/test/resource/gms_common_function/USB_HUB_PORT.txt |grep "${test_type}[0-9][0-9]*" |sed -n "${integer}p" \
# |sed 's/^.*${test_type}[0-9][0-9]*://g'"
# port=$(cat ~/test/resource/gms_common_function/USB_HUB_PORT.txt |grep "${test_type}[0-9][0-9]*" |sed -n "${integer}p" \
# |sed 's/^.*$test_type[0-9][0-9]*://g')
# echo $port
# cat ~/test/resource/gms_common_function/SerialNum/SerialNum_info.txt |grep -A 5 "${port}"| sed -n "2p"\
# | sed "s/^.*SerialNumber=//g"|cut -d " " -f1>>~/test/resource/gms_common_function/SerialNum/${test_type}_serial.txt
# done
# done