Answer the question
In order to leave comments, you need to log in
How to do proper client list output from dhcpd in centos?
Actually, dhcpd works on centos 6.4. Quite often, you need to display a list, find out the poppy address or ip.
What is the best script to do this?
now there is
cat /var/lib/dhcpd/dhcpd.lease | grep -e lease -e client-hostname
but it turns out that each value is on a new line. It would be nice to have this kind of
ip-client-hostname-mac
Answer the question
In order to leave comments, you need to log in
#!/bin/bash
cat /var/lib/dhcpd/dhcpd.leases | awk '/lease/ || /client-hostname/ || /hardware/ || /}/' | awk '!/uid/' | sed 's/lease/Client-IP /g' | sed 's/{//'g | sed 's/hardware ethernet/MAC /g' | sed 's/client-hostname/NAME/g' | sed 's/}/---------------------------------------------------- ---------------/g' | sendmail [email protected]
More or less workaround:
------------------------------- ----------------------
Client-IP 192.168.1.1
MAC ff:ff:ff:ff:ff:ff;
NAME "PC-1";
MAC ff:ff:ff:ff:ff:ff;
NAME "PC-1";
-------------------------------------------------- ---------
Client-IP 192.168.1.1
MAC ff:ff:ff:ff:ff:ff;
-------------------------------------------------- ---------
Client-IP 192.168.1.1
MAC ff:ff:ff:ff:ff:ff;
NAME "PC-1";
-------------------------------------------------- ---------
I have some ideas, but in fact, the knowledge of awk is not enough
lease 192.168.1.10 {
starts 2 2013/12/03 10:56:22;
ends 2 2013/12/03 22:56:22;
cltt 2 2013/12/03 10:56:22 AM;
binding state active;
next binding state free;
hardware ethernet ff:ff:ff:ff:ff:ff;
uid "\001\000'\016\021\352R";
client-hostname "Finans";
}
select the lines where there is lease, hardware ethernet, client-hostname and select the second column in them. but how to make not a line break but an output to a line for each client. I suspect it's not an easy decision.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question