Tools to convert dhcpd.conf -> CSV text file
Dear list,
to check regularily on new / misconfigured clients,
I use mostly grep and other cl-tools.
Now, I am looking for a more sophisticated tool to
get a csv from /var/lib/dhcp3/dhcpd.leases
Apparently, there are some tools like dhcpd status,
but most are thought to be run as cgi module.
Eventually I found this script and adapted it to my
needs, so feel free to work this out.
Regards
Ralf
[1]
http://stackoverflow.com/questions/2142824/parse-a-dhcpd-lease-file-with-bash
#### leases2csv.sh ################################
## 1 parameter needed: file with your leases
## depends on: awk
echo "ip;hostname;ether;uid"
awk 'BEGIN{
RS="}"
FS="\n"
}
/lease/{
for(i=1;i<=NF;i++){
gsub(";","",$i)
if ($i ~ /lease/) {
m=split($i, IP," ")
ip=IP[2]
}
if( $i ~ /hardware/ ){
m=split($i, hw," ")
ether=hw[3]
}
if ( $i ~ /client-hostname/){
m=split($i,ch, " ")
hostname=ch[2]
}
if ( $i ~ /uid/){
m=split($i,ui, " ")
uid=ui[2]
}
}
print ip ";"hostname ";"ether ";"uid
} ' "$1"
#### EOF #########################################
Reply to: