[CS-FSLUG] Shell Scripting A Solution to Network Monitoring

Josiah Ritchie jritchie at bible.edu
Mon Aug 2 07:45:50 CDT 2004


OOhh... I figured there was a cleaner way of doing this.

What does gsub("[;\"]", "", host) do?

On Sat, 2004-07-31 at 14:02, Robert W. wrote:
> 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
> 
> _______________________________________________
> ChristianSource FSLUG mailing list
> Christiansource at ofb.biz
> http://cs.uninetsolutions.com





More information about the Christiansource mailing list