linux电脑获取固定hub端口的设备序列号

获取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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

听他风吟

赏个赞呗

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值
>