[Dnsmasq-discuss] Reg: Info related to leases file
Simon Kelley
simon at thekelleys.org.uk
Wed Sep 25 21:57:16 BST 2013
On 25/09/13 21:52, Lonnie Abelbeck wrote:
>
>
> Hi Simon,
>
> May I be so bold to offer a couple tweaks to your script... :-)
Of course, I make no claims to shell scripting expertise, and what I
posted was very much proof-of-concept anyway. Add error checking as
required.....
>
> 1) Use 'sed' -i' instead of 'grep -v' plus a temp file
>
> 2) Include the trailing 'space' in the sed/grep match (Important)
>
> 3) Escape the dot's in a IPv4 address in the sed/grep match (unlikely to be a problem, but possible)
>
> 4) Add many quotes, (agree some are not required)
>
> =========================
> #!/bin/bash
>
> action="$1"
> mac="$2" # IPv4
> ip="$3"
>
> STATUS_FILE="/tmp/dnsmasq-ip-mac.status"
>
> if [ -n "$DNSMASQ_IAID" ]; then
> mac="$DNSMASQ_MAC" # IPv6
> fi
>
> if [ "$action" = "add" -o "$action" = "old" -o "$action" = "del" ]; then
> if [ -f "$STATUS_FILE" ]; then
> sed -i "/^${ip//./\.} / d" "$STATUS_FILE"
> fi
> if [ "$action" = "add" -o "$action" = "old" ]; then
> echo "$ip $mac">> "$STATUS_FILE"
> fi
> fi
> =========================
Much better. Many thanks.
Cheers,
Simon.
>
> Lonnie
>
>
More information about the Dnsmasq-discuss
mailing list