I am wondering if I can use one grep command for the following situation.
I have a dhcpd.conf file in which DHCP hosts are defined. Given the host name, I need to find its MAC address in the dhcpd.conf file. I need to use it to disable its PXE boot configuration, but this is not part of this question.
The file syntax is homogeneous, but I still want to make it a little dumb. Here's how nodes are defined:
host client1 { hardware ethernet 12:23:34:56:78:89; fixed-address 192.168.1.11; filename "pxelinux.0"; }
host client2 { hardware ethernet 23:34:45:56:67:78; fixed-address 192.168.1.12; filename "pxelinux.0"; }
host client3 { hardware ethernet AB:CD:EF:01:23:45; fixed-address 192.168.1.13; filename "pxelinux.0"; }
host client4 { hardware ethernet C1:CA:88:FA:F4:90; fixed-address 192.168.1.14; filename "pxelinux.0"; }
We assume that all configurations occupy only one line, even if the syntax dhcpd.conf allows you to split the parameters into several lines. Assume that the order of options may vary.
I came up with the following grep command:
grep -o "^[^#]*host.*${DHCP_HOSTNAME}.*hardware ethernet.*..:..:..:..:..:..;" /etc/dhcp/dhcpd-hosts.conf
, , MAC-.
, :
host client1 { hardware ethernet 12:23:34:56:78:89;
! , MAC- . , grep, cut, awk MAC- . , grep ? , , , "..:..:..:..:..:.." MAC-.
, ( grep), MAC- . - , "grep... | grep..." "grep... | cut..." ..
, , , , .
.