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.
Jerry
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.
Jerry
There's multiple spaces in the output that cut is hitting - use tr to reduce them.
ifconfig | grep eth0 | tr -s ' ' ' ' | cut -d ' ' -f 5
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1
Toby Bluhm wrote:
There's multiple spaces in the output that cut is hitting - use tr to reduce them.
ifconfig | grep eth0 | tr -s ' ' ' ' | cut -d ' ' -f 5
Or:
ifconfig | grep eth0 | cut -d ' ' -f 11
On Thu, Feb 28, 2008 at 2:56 PM, Max Hetrick maxhetrick@verizon.net wrote:
Toby Bluhm wrote:
There's multiple spaces in the output that cut is hitting - use tr to reduce them.
ifconfig | grep eth0 | tr -s ' ' ' ' | cut -d ' ' -f 5
Or:
ifconfig | grep eth0 | cut -d ' ' -f 11
For the sed people, this should also work :
ifconfig | grep eth0 | sed -e "s/^.*HWaddr (.*)$/\1/"
Regards, Tim
ip is probably a better tool (than ifconfig)
ip link show eth0 | tr -s " " | cut -d" " -f3
Max Hetrick wrote:
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1
Toby Bluhm wrote:
There's multiple spaces in the output that cut is hitting - use tr to reduce them.
ifconfig | grep eth0 | tr -s ' ' ' ' | cut -d ' ' -f 5
Or:
ifconfig | grep eth0 | cut -d ' ' -f 11
-----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.5 (GNU/Linux)
iD8DBQFHxr2hIXSX/6LmsXkRAuZcAJ9Yzxx2vuPhj8JEa1NIjrtXbpmEQQCfangU eD8VSzg6fUrEN/jgPULWdEE= =+Bez -----END PGP SIGNATURE----- _______________________________________________ CentOS mailing list CentOS@centos.org http://lists.centos.org/mailman/listinfo/centos
On Thu, Feb 28, 2008 at 08:56:49AM -0500, Max Hetrick enlightened us:
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1
Toby Bluhm wrote:
There's multiple spaces in the output that cut is hitting - use tr to reduce them.
ifconfig | grep eth0 | tr -s ' ' ' ' | cut -d ' ' -f 5
Or:
ifconfig | grep eth0 | cut -d ' ' -f 11
Or reduce the number of pipes by one:
ifconfig eth0 | awk '/HWaddr/ { print $5 }'
Matt
On Thu, 2008-02-28 at 08:51 -0500, Toby Bluhm 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.
Jerry
There's multiple spaces in the output that cut is hitting - use tr to reduce them.
ifconfig | grep eth0 | tr -s ' ' ' ' | cut -d ' ' -f 5
/sbin/ifconfig | grep eth0 | awk '{ print $5 }'
for the lazy way or "man gawk" to see how to select and print and skip lines of no interest, eliminating the grep.
HTH
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'
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'
-- Les Mikesell lesmikesell@gmail.com
Specifying eth0 as ifconfig parameter also would be better once there is eth0:0, eth0:1, etc. Otherwise multiple lines would be returned.
Wojtek
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}'
I mean, doesn't everyone use lower-case MACs in dhcpd.conf? :-)
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 }'
ip also has a one-line output mechanism:
ip -o link show
...
I do wish the mothership would update its standard network configuration scripts to use ip(8) rather than the legacy ifconfig(8). Rather than using the legacy eth0:1 style interface aliases, allow a single /etc/sysconfig/network-scripts/ifcfg-eth0 to contain a list of aliases which get set with
ip addr add ......
ditto optional static routes could be set with
ip route add ...
On Fri, 29 Feb 2008, John R Pierce wrote:
ip also has a one-line output mechanism:
ip -o link show
...
I do wish the mothership would update its standard network configuration scripts to use ip(8) rather than the legacy ifconfig(8). Rather than using the legacy eth0:1 style interface aliases, allow a single /etc/sysconfig/network-scripts/ifcfg-eth0 to contain a list of aliases which get set with
ip addr add ......
ditto optional static routes could be set with
ip route add ...
The great mothership fulfilled your wishes retrospectively if you use route-eth0 to set your routes :) Eg.
1.2.3.4 via 4.3.2.1 8.4.2.0/24 via 7.5.3.1
would be the same as:
route add -host 1.2.3.4 gw 4.3.2.1 route add -net 8.4.2.0 netmask 255.255.255.0 gw 7.5.3.1
On Thu, Feb 28, 2008 at 8:47 AM, Jerry Geis geisj@pagestation.com 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.
ifconfig -a | awk '/eth0/ {print $5}'
should work even if eth0 is not 'UP'