[CS-FSLUG] Shell Scripting A Solution to Network Monitoring
Robert W.
robertwo at access-4-free.com
Sat Jul 31 13:02:59 CDT 2004
On 07/30/2004 11:56:14 AM, Josiah Ritchie wrote:
> I managed to do what I wanted with a one-liner (if you can call it
> that being so long. :-)
>
> cat /var/lib/dhcp/dhcpd.leases|tr -d "\n"|tr "}" "\n"|tr -d "\""|tr -
> d
> ";"|grep -v '^#'|gawk '{print $2 ": " $25 " = " $21}'
I couldn't resist :) Here's an awk script that does the same thing as
your command line (at least it did with the one test I ran).
===== BEGIN SCRIPT =====
# Extract the client's IP address...
/lease / { ip = $2 }
# Extract the client's hostname...
/client-hostname / { host = $2; gsub("[;\"]", "", host) }
# Extract the ethernet MAC address...
/hardware ethernet / { mac = $3; gsub(";", "", mac) }
# At the end of each "lease" record, print the network information.
/\}/ { print ip ": " host " = " mac }
===== END SCRIPT =====
Extract the script to the file "dhcp.awk" (without the "===== BEGIN
SCRIPT =====" and "===== END SCRIPT =====" lines). Invoke awk like so:
gawk -f dhcp.awk /var/lib/dhcp/dhcpd.leases
--
Robert W.
robertwo at access-4-free.com
And we know that in all things God works for the good of those who love
him, who have been called according to his purpose. -- Romans 8:28
More information about the Christiansource
mailing list