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

Rowland Penny rpenny at samba.org
Thu Mar 29 19:29:39 UTC 2018


On Thu, 29 Mar 2018 21:15:04 +0200
Harry Jede <walk2sun at arcor.de> wrote:

> 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

Point taken, but you don't need to use 'egrep', grep works just the
same.

> 
> 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
> 

'sed' (like perl) is only simple if you understand it and it isn't
worth the gain.

Rowland




More information about the samba mailing list