mac.sh

#!/bin/bash

ip a s | awk 'BEGIN{print "local machine MAC address:"}/^[0-9]/{print $2;getline;if($0~/link\/ether/){print $2}}' | grep -v lo:

echo
echo "local machine MAC address:"

ip a s |grep link/ether | awk -F" " '{print $2}'

验证:

[root@logstash ~]# sh mac.sh 
local machine MAC address:
ens32:
00:0c:29:ed:c6:f8
docker_gwbridge:
02:42:5b:48:16:ff
docker0:
02:42:f9:f5:b7:3a
ens32.200@ens32:
00:0c:29:ed:c6:f8
ens32.100@ens32:
00:0c:29:ed:c6:f8
vethce5b18f@if10:
1a:da:42:e6:ec:42

local machine MAC address:
00:0c:29:ed:c6:f8
02:42:5b:48:16:ff
02:42:f9:f5:b7:3a
00:0c:29:ed:c6:f8
00:0c:29:ed:c6:f8
1a:da:42:e6:ec:42
[root@logstash ~]#