forget leases

Mike the.lists at mgm51.com
Thu Jul 23 15:28:43 UTC 2015


On 7/23/2015 10:59 AM, richard lucassen wrote:
> Ok, thnx everyone, I'll write a nice shell script that parses the leases
> file ...

If it's any help to get you started, below is my script that displays
the IPv4 leases for my setup (I run it on FreeBSD 10.1)...  :)

(version without line-wrapping is available here:
  https://archive.mgm51.com/kea-show-leases.zip )


===============================

#!/bin/sh


set -e
#set -xv

LeaseFile=/var/db/kea/kea-leases4.csv
Tmp1File=$(mktemp /tmp/show-lease.XXXXXX)

PrintFormat="%-15s %-17s %7s %-15s %-15s %-15s %-15s\n"

# renew halfway through the lease
RenewFactor=2


NumRecsToShow=45
test $1x = allx && NumRecsToShow=999999


# kea lease record
#
address,hwaddr,client_id,valid_lifetime,expire,subnet_id,fqdn_fwd,fqdn_rev,hostname
# 10.20.2.131,00:30:f4:c1:02:1e,01:00:30:f4:c1:02:1e,80000,1429363284,1,0,0,

tail -n +2 /var/db/kea/kea-leases4.csv | tail -r > ${Tmp1File}


printf "${PrintFormat}" "IPAddr" "HWAddr" "Lease" "Start" "Renew"
"Expire" "Hostname"

RecCount=0
while IFS=, read IPAddr HWAddr ClientID LeaseLenSecs ExpireSecs SubnetID
FQDNFwd FQDNRev HostName
do
	StartSecs=$((${ExpireSecs} - ${LeaseLenSecs}))
	RenewLenSecs=$((${LeaseLenSecs} / ${RenewFactor}))
	RenewSecs=$((${ExpireSecs} - ${RenewLenSecs}))
	StartDate=$(date -j -r ${StartSecs} +%Y%m%dT%H%M%S)
	RenewDate=$(date -j -r ${RenewSecs} +%Y%m%dT%H%M%S)
	ExpireDate=$(date -j -r ${ExpireSecs} +%Y%m%dT%H%M%S)
	printf "${PrintFormat}" \
	   ${IPAddr} ${HWAddr} ${LeaseLenSecs} ${StartDate} ${RenewDate}
${ExpireDate} ${HostName}
	RecCount=$((${RecCount} + 1))
	test ${RecCount} -ge ${NumRecsToShow} && break
done < ${Tmp1File}


test ${Tmp1File} && rm ${Tmp1File}

=========================================


More information about the dhcp-users mailing list