Re: GRabbing MAC address

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]



On Thu, 28 Feb 2008, Paul Heinlein wrote:

On Thu, 28 Feb 2008, Wojtek Pilorz wrote:
On Thu, Feb 28, 2008 at 08:13:17AM -0600, Les Mikesell wrote:
Jerry Geis wrote:
I am trying to grab the mac address for eth0 on centos 5.1 with

ifconfig | grep eth0 | cut -d ' ' -f 5 and I dont get anything.

What am I not doing right?

ifconfig | grep eth0 | cut -d ' ' -f 1 gives me eth0 but anything else like -f 2, -f 3 etc I get nothing.

If sed had been invented first, we wouldn't need grep.

ifconfig |sed -n -e 's/eth0.*\(..:..:..:..:..:..\)/\1/p'

Or awk! :-) And you can ditch ifconfig entirely and use /sbin/ip,
which defaults to a lower-case version of the MAC rather than the
upper-case presentation used by ifconfig:

 ip link show eth0 | awk '/ether/ {print $2}'

ip also has a one-line output mechanism:

	ip -o link show

which could lead you to:

	ip -o link show | awk '/ether/ { print $2 " " $11 }'

--
--   dag wieers,  dag@xxxxxxxxxx,  http://dag.wieers.com/   --
[Any errors in spelling, tact or fact are transmission errors]
_______________________________________________
CentOS mailing list
CentOS@xxxxxxxxxx
http://lists.centos.org/mailman/listinfo/centos

[Index of Archives]     [CentOS]     [CentOS Announce]     [CentOS Development]     [CentOS ARM Devel]     [CentOS Docs]     [CentOS Virtualization]     [Carrier Grade Linux]     [Linux Media]     [Asterisk]     [DCCP]     [Netdev]     [Xorg]     [Linux USB]
  Powered by Linux