• linux 获取PciE设备列表(脚本)


     1 #!/bin/bash
     2 #
     3 #通过dmidecode获取有关“Designation:、Type:、Current Usage:、Length:、Bus Address:的信息,并输出到/tmp/dmidecode_slot.log文件内
     4 dmidecode -t slot | grep -E "Designation:|Type:|Current Usage:|Length:|Bus Address:" | sed 's/^[ \t]*//g' | sed '/^$/d' | grep -v "\-\-" \
     5  > /tmp/dmidecode_slot.log
     6  #在/tmp/dmidecode_slot.log文件内删除x8 x16 x2 x4每行第一份匹配的值
     7 sed -i 's/x8 //;s/x16 //;s/x2 //;s/x4 //' /tmp/dmidecode_slot.log
     8 sed -i 's/Express //' /tmp/dmidecode_slot.log
     9 #获取bus address值,并赋值给busid变量
    10 busid=`cat /tmp/dmidecode_slot.log | grep "Bus Address:" | awk -F ":" '{print $3":"$4}'|awk -F "." '{print $1}'| sort | uniq`
    11 #通过busid循环出对应的pcie插卡设备名称,将空槽位设置未N/A,并将其值输出到 /tmp/dmidecode_slot.log文件里的bus addres 的下一行
    12 for i in $busid
    13  do 
    14 # pci_devices=$(lspci | grep "$i" |awk -F ":" '{print $NF}'| sort |uniq -c | awk 'NF{NF--}1'| awk 'NF{NF--}1')
    15  pci_devices=$(lspci | grep "$i" |awk -F ":" '{print $NF}'| sort |uniq -c|sed s'/^ *//g')
    16 
    17  if [ -n "$pci_devices" ]
    18  then 
    19  :
    20  else 
    21  pci_devices="N/A" 
    22  fi
    23  sed -i '/'"$i"'/a'"pcie_devices: $pci_devices"'' /tmp/dmidecode_slot.log
    24 done
    25 #
    26 #
    27 #去除标题,保留内容,并重新输出到dmidecode_slot1,log
    28 cat /tmp/dmidecode_slot.log |awk -F ": " '{print $2}' > /tmp/dmidecode_slot1.log
    29 #
    30 #去掉busid的0000:
    31 cat /tmp/dmidecode_slot1.log | grep 0000:| sed -i 's/\.0//;s/0000://' /tmp/dmidecode_slot1.log
    32 #添加格式化输出分割线
    33 sed -i 's/^/| &/g' /tmp/dmidecode_slot1.log
    34 #
    35 #将文件中的空格换成下划线(_),方便printf对其格式化输出
    36 sed -i 's/ /_/g' /tmp/dmidecode_slot1.log
    37 #将dmidecode_slot1.log内容转换为一行,并赋值为pci_list
    38 pci_list=$(echo `cat /tmp/dmidecode_slot1.log`)
    39 #清屏
    40 clear
    41 #格式化输出
    42 echo -e "\033[033m
    43 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++  
    44 +                                      ____  __________           __    _      __                                                           +  
    45 +                                     / __ \/ ____/  _/__        / /   (_)____/ /_                                                          +  
    46 +                                    / /_/ / /    / // _ \______/ /   / / ___/ __/                                                          +  
    47 +                                   / ____/ /____/ //  __/_____/ /___/ (__  ) /_                                                            +  
    48 +                                  /_/    \____/___/\___/     /_____/_/____/\__/   v1.0-2018.10.17                                          +  
    49 +                                                                                                                                           +\033[0m"
    50 #
    51 echo -e "\033[33m+------------+------------+-----------+--------+----------+---------------------------------------------------------------------------------+\033[0m" > /tmp/pcie_list.log
    52 echo -e "\033[33m| SOLT       | TPYE       | USAGE     | LENGTH | BUS ADD  | DEVIECS                                                                         |\033[0m" >> /tmp/pcie_list.log
    53 echo -e "\033[33m+------------+------------+-----------+--------+----------+---------------------------------------------------------------------------------+\033[0m" >> /tmp/pcie_list.log
    54 printf "%-12s %-12s %-11s %-8s %-10s %-1s\n" $pci_list >> /tmp/pcie_list.log
    55 echo -e "\033[33m+------------+------------+-----------+--------+----------+---------------------------------------------------------------------------------+\033[0m" >> /tmp/pcie_list.log
    56 #将文件中的下划线(_)换成空格,还原输出
    57 sed -i 's/_/ /g' /tmp/pcie_list.log
    58 #将结果输出到屏幕上
    59 cat /tmp/pcie_list.log
    60 #删除临时文件
    61 #rm -rf /tmp/dmidecode_slot1.log /tmp/dmidecode_slot.log
  • 相关阅读:
    如何创建支持64位的安装程序
    SharePoint Server 2013开发之旅(四):配置工作流开发和测试环境
    SharePoint Server 2013开发之旅(三):为SharePoint Server配置App开发、部署、管理环境
    SharePoint Server 2013开发之旅(二):使用在线的开发人员网站进行SharePoint App开发
    SharePoint Server 2013开发之旅(一):新的开发平台和典型开发场景介绍
    在WPF应用程序中利用IEditableObject接口实现可撤销编辑的对象
    一个在ASP.NET中利用服务器控件GridView实现数据增删改查的例子
    关于未捕获异常的处理(WPF)
    牛刀小试:使用Reactive Extensions(Rx),对短时间内多次发生的事件限流
    如何对SharePoint网站进行预热(warmup)以提高响应速度
  • 原文地址:https://www.cnblogs.com/coolYuan/p/15774499.html
Copyright © 2020-2023  润新知