[Samba] dhcp lease time hardware in script at dhcpd/Bind/Samba wiki page

Harry Jede walk2sun at arcor.de
Thu Mar 29 19:15:04 UTC 2018


Hi Rowland,

> You could try adding something like this near to the top of
> dhcp-dyndns.sh:
> 
> TTL=$(cat /etc/dhcp/dhcpd.conf | grep 'max-lease-time' | awk -F ';'
> '{print $1}' | awk '{print $NF}')
> 
> Then replace the '3600' with '$TTL'

Users like comments in their config files. Your script:

cat /etc/dhcp/dhcpd.conf | grep 'max-lease-time' | awk -F ';' '{print $1}' | awk '{print $NF}'
7200
7200


better is this:

cat /etc/dhcp/dhcpd.conf | egrep '^\s*max-lease-time' | awk -F ';' '{print $1}' | awk '{print $NF}'
7200

So this matches:

max-lease-time
 max-lease-time
	max-lease-time

but not:
# max-lease-time

btw
cheaper is sed and i am a sed fan (keep it simple):

time cat /etc/dhcp/dhcpd.conf|sed -nre 's/^\s*max-lease-time\s*([0-9]+).*/\1/p'
7200

real	0m0,004s
user	0m0,003s
sys 	0m0,004s


time cat /etc/dhcp/dhcpd.conf | grep 'max-lease-time' | awk -F ';' '{print $1}' | awk '{print $NF}'
7200
7200

real	0m0,006s
user	0m0,004s
sys 	0m0,012s


> Rowland


-- 

Gruss
	Harry Jede


More information about the samba mailing list