【发布时间】:2015-07-15 17:48:47
【问题描述】:
在 linux 平台上,我需要从 cli 中找到给定名称的接口的 product_id、vendor_id 和地址。我正在使用以下命令来查找它:
# to find addr:
pci_interface_addr0=$(ethtool -i $eth0 | grep -i bus-info | tail -c 8)
# to find ids:
complete_id=$(lspci -nvv | grep $pci_interface_addr0 | awk '{print $3}')
vendor_id=$(echo $complete_id | cut -d \: -f 1)
product_id=$(echo $complete_id | cut -d \: -f 2)
有没有更好的方法来解决这个问题?因为我有像上面的 tail -c 8 这样的硬编码值。
这可以在python中完成吗?由于父程序主要是一个python模块。
感谢任何好的输入!
【问题讨论】:
标签: python linux bash awk ethernet