On Mon, Mar 23, 2009 at 12:05:07PM +0100, lizard wrote:

> erf - again, this time with complete paste :)
> 
> #!/bin/sh
> file=/etc/tinc/$NETNAME/hosts/$NODE
> echo $file
> grep -Fq "#dynamic" $file || exit 0
> grep -Fq "Address = $REMOTEADDRESS" $file && exit 0
> grep -Fv "#dynamic" $file > $file.new
> echo "Address = $REMOTEADDRESS #dynamic" >> $file.new
> mv $file.new $file

Comments can only start at the beginning of a line, so putting #dynamic at the
end of the line might not work. You can vary whitespace if you want to
distinguish between manual and dynamic Addresses. To top you, the following
script that remembers the last 3 dynamic addresses and does not overwrite the
host config file when something goes wrong:

#!/bin/sh
file=/etc/tinc/$NETNAME/hosts/$NODE
grep -Fq "Address  =  $REMOTEADDRESS" $file && exit 0
grep -Fv "Address  =  " $file > $file.new &&\
echo "Address  =  $REMOTEADDRESS" >> $file.new &&\
grep -Fm 2 "Address  =  " $file >> $file.new &&\
mv $file.new $file

-- 
Met vriendelijke groet / with kind regards,
     Guus Sliepen <[email protected]>

Attachment: signature.asc
Description: Digital signature

_______________________________________________
tinc mailing list
[email protected]
http://www.tinc-vpn.org/cgi-bin/mailman/listinfo/tinc

Reply via email to