From owner-freebsd-questions Thu Feb 21 1: 6:36 2002 Delivered-To: freebsd-questions@freebsd.org Received: from kabel203069.kabel.utwente.nl (kabel203069.kabel.utwente.nl [130.89.203.69]) by hub.freebsd.org (Postfix) with ESMTP id 68F4937B402 for ; Thu, 21 Feb 2002 01:06:32 -0800 (PST) Received: by kabel203069.kabel.utwente.nl (Postfix, from userid 1000) id 73D761F80; Thu, 21 Feb 2002 10:06:30 +0100 (CET) Date: Thu, 21 Feb 2002 10:06:30 +0100 From: Rogier Steehouder To: "B.K. DeLong" Cc: freebsd-questions@freebsd.org Subject: Re: BASH programming question Message-ID: <20020221100630.A644@localhost> Mail-Followup-To: Rogier Steehouder , "B.K. DeLong" , freebsd-questions@freebsd.org References: <20020221000224.A32489@nigsch.com> <5.1.0.14.2.20020220160637.02763050@pop.earthlink.net> <5.1.0.14.2.20020220160637.02763050@pop.earthlink.net> <20020220224520.A31541@nigsch.com> <5.1.0.14.2.20020220165911.01e189a0@pop.earthlink.net> <20020221000224.A32489@nigsch.com> <20020220231436.GA658@raggedclown.net> <5.1.0.14.2.20020220214132.029df6f0@pop.earthlink.net> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.2.5.1i In-Reply-To: <5.1.0.14.2.20020220214132.029df6f0@pop.earthlink.net>; from bkdelong@pobox.com on Wed, Feb 20, 2002 at 09:43:53PM -0500 Sender: owner-freebsd-questions@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.ORG On 20-02-2002 21:43 (-0500), B.K. DeLong wrote: > Thanks for all your help - here's the finished script. I know the comments > are a bit anal but I hate having to look all over the place for the same > info again. > > Comments welcome: Well, don't mind if I do :-) > #!/usr/local/bin/bash Why not use plain /bin/sh ? I haven't seen anything bash-specific. #!/bin/sh # Having machine-specific variables in front eases migrating later. IPFILE='/usr/local/bin/.currentip' SERVERNAME='firewall.internal.brain-stream.com' > ifconfig xl0 | grep "inet " | cut -f2 -d" " > /usr/local/bin/.newip NEWIP=$(ifconfig xl0 | grep "inet " | cut -f2 -d" ") # saves writing a file. > if diff /usr/local/bin/.newip /usr/local/bin/.currentip; then exit 0; read OLDIP < ${IPFILE} if [ ${OLDIP} != ${NEWIP} ]; then # saves running 1 program: read is an internal command. > else > cat /usr/local/bin/.newip > /usr/local/bin/.currentip; > mail -s "New IP for firewall.internal.brain-stream.com " ip < > /usr/local/bin/.currentip; > echo "A New IP has been found" > exit 0 > fi echo ${NEWIP} > ${IPFILE} mail -s "New IP for ${SERVERNAME}" ip < ${IPFILE} echo 'A New IP has been found' fi All in all it uses some extra variables, but saves starting one other program and only leaves one file behind. If you use DHCP, you can put all this in /etc/dhclient-exit-hooks and then the new IP is in ${new_ip_address}. That will save running another three programs. With kind regards, Rogier Steehouder -- ___ _ -O_\ // | / Rogier Steehouder //\ / \ r.j.s@gmx.net // \ <---------------------- 25m ----------------------> To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-questions" in the body of the message