2012-09-30 14 views
0

我正在編寫腳本來打印ifconfig的ethtool詳細信息。如何削減ifconfig來單獨獲取eth *細節?

輸出樣本應該是從命令ifconfig是什麼樣子,

eth0 
eth1 
eth2 

我一直在使用下面的命令嘗試,

[email protected]# ifconfig | cut -d ":" -f 1 

但可能無法實現相同。

其實,我需要得到這些eth*並傳遞

[email protected]# ethtool <arg1> where arg1=eth* 

,得到的結果:-)可以請你幫我從命令ifconfig獲得收成。 ?

回答

0

隨着grep & ifconfig

ifconfig | grep -o '^eth[0-9]\+' 

或只grep

grep -oP '^ *\Keth[0-9]+' /proc/net/dev 
+0

非常感謝:-)兩個工程.. – San

1

$ awk -F: '$1 ~ "eth" { print $1 }' /proc/net/dev 
    eth0 
+0

謝謝!它的工作原理:-) – San