msoliver
(usa Debian)
Enviado em 23/09/2017 - 13:45h
Lucas Peregrino escreveu:
grep -E -A3 'clients;$' /etc/dhcp/dhcpd.conf |awk -F '[" " "\n"]' 'BEGIN{RS="--\n";} {print $26 $27}'unknown-clients;
unknown-clients;
unknown-clients;
unknown-clients;
unknown-clients;
unknown-clients;
unknown-clients;
unknown-clients;
unknown-clients;
unknown-clients;
unknown-clients;
unknown-clients;
unknown-clients;
unknown-clients;
unknown-clients;
unknown-clients;
unknown-clients;
unknown-clients;
unknown-clients;
unknown-clients;
unknown-clients;
grep -E -A3 'ethernet|fixed-address;$' /etc/dhcp/dhcpd.conf | awk -F '[" " "\n"]' 'BEGIN {RS="--\n";} {print $26 $27}'
ethernet54:9f:35:0d:0c:ae;
ethernet08:00:27:81:10:58;
ethernet08:00:27:f7:02:af;
ethernet08:00:27:bf:5c:f9;
ethernet00:bb:46:14:4f:b9;
ethernet00:1d:ba:92:64:b6;
ethernet70:4d:7b:62:90:63;
ethernet48:5b:39:ce:fd:0b;
ethernet94:de:80:03:b0:db;
ethernet50:e5:49:f3:9c:1f;
ethernet4c:ed:de:c5:1e:7f;
ethernete0:b9:a5:0c:3c:d6;
ethernet6c:62:6d:30:b0:df;
ethernet44:6d:57:33:74:5d;
ethernetac:16:2d:34:72:68;
ethernet00:00:00:00:00:01;
etherneta8:7c:01:10:25:ca;
ethernet14:a3:64:9c:b9:dd;
ethernetc8:08:e9:44:70:97;
ethernet00:0a:eb:95:0e:e9;
ethernet00:27:22:8e:a7:e8;
fiz desta outra forma deu certo mas estranho q linha n fico por igual.
grep -E -A3 "ethernet|fixed-address" /etc/dhcp/dhcpd.conf | awk 'BEGIN {FS="\n";RS="\n--";} {print $1,$2,$3}'
hardware ethernet 54:9f:35:0d:0c:ae; fixed-address 192.168.30.253; }
hardware ethernet 08:00:27:81:10:58; fixed-address 192.168.30.254;
hardware ethernet 08:00:27:f7:02:af; fixed-address 192.168.30.252;
hardware ethernet 08:00:27:bf:5c:f9; fixed-address 192.168.30.251;
hardware ethernet 00:bb:46:14:4f:b9; fixed-address 192.168.30.250;
hardware ethernet 00:1d:ba:92:64:b6; fixed-address 192.168.30.30;
hardware ethernet 70:4d:7b:62:90:63; fixed-address 192.168.30.31;
hardware ethernet 48:5b:39:ce:fd:0b; fixed-address 192.168.30.40;
hardware ethernet 94:de:80:03:b0:db; fixed-address 192.168.30.42;
hardware ethernet 50:e5:49:f3:9c:1f; fixed-address 192.168.30.43;
hardware ethernet 4c:ed:de:c5:1e:7f; fixed-address 192.168.30.44;
hardware ethernet e0:b9:a5:0c:3c:d6; fixed-address 192.168.30.53;
hardware ethernet 6c:62:6d:30:b0:df; fixed-address 192.168.30.54;
hardware ethernet 44:6d:57:33:74:5d; fixed-address 192.168.30.55;
hardware ethernet ac:16:2d:34:72:68; fixed-address 192.168.30.56;
hardware ethernet 00:00:00:00:00:01; fixed-address 192.168.30.57;
hardware ethernet a8:7c:01:10:25:ca; fixed-address 192.168.30.60;
hardware ethernet 14:a3:64:9c:b9:dd; fixed-address 192.168.30.61;
hardware ethernet c8:08:e9:44:70:97; fixed-address 192.168.30.79;
hardware ethernet 00:0a:eb:95:0e:e9; fixed-address 192.168.30.70;
hardware ethernet 00:27:22:8e:a7:e8; fixed-address 192.168.30.71;
Lucas, boa tarde.
A Intenção do comando "grep" é "fazer um arquivo padrão".
Copiei e colei o "/etc/dhcp/dhclient.conf" que vc postou . . . .
Com o comando:
grep -E -A1 'hardware ethernet' /etc/dhcp/dhclient.conf|sed 's/^--$//'
#PEGUE a linha que tem a string "'hardware ethernet", mostre a linha abaixo e troque "--" por "NADA"
OBTENHO:
hardware ethernet 00:bb:46:14:4f:b9;
fixed-address 192.168.3.250;
hardware ethernet 00:1d:ba:92:64:b6;
fixed-address 192.168.3.30;
hardware ethernet 78:24:af:78:3c:c6;
fixed-address 192.168.3.31;
Direcionando para o awk, "pego" somente os IP's e os MAC's.
grep -E -A1 'hardware ethernet' CONF.txt|sed 's/^--$//'|awk 'BEGIN{FS=" "; RS="\n\n";} {print $3,$5}'
#awk 'BEGIN{FS=" "; RS="\n\n";} {print $3,$5}' => Indico que o SEPARADOR de CAMPO é o " ", e o SEPARADOR de REGISTRO são DUAS LINHAS , printo os campos 3 e 5.
É Isso.
Att.:
Marcelo Oliver