Thursday, August 5, 2010
examples on ifconfig, grep and awk
These examples are about "read ip address of linux interfaces" entry;
1) get interface list;
root@ismail-laptop:/usr/lib/cgi-bin# ifconfig | grep "Link encap"| awk -F ' ' '{print $1}'
eth0
eth2
lo
ppp0
root@ismail-laptop:/usr/lib/cgi-bin#
2) get mac address from each interfaces;
root@ismail-laptop:/usr/lib/cgi-bin# ifconfig | grep "HWaddr" | awk -F ' ' '{print $1 " - " $5}'
eth0 - 00:26:b9:9a:65:06
eth2 - c4:17:fe:1e:fe:6d
root@ismail-laptop:/usr/lib/cgi-bin#
3) get upload/download size for specific interface;
root@ismail-laptop:/usr/lib/cgi-bin# ifconfig ppp0 | grep "RX bytes" | awk -F ' ' '{print "download size: " $3 " " $4}'
download size: (5.8 MB)
root@ismail-laptop:/usr/lib/cgi-bin# ifconfig ppp0 | grep "RX bytes" | awk -F ' ' '{print "download size: " $7 " " $8}'
download size: (2.3 MB)
root@ismail-laptop:/usr/lib/cgi-bin#
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment
Thanks