Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 20 Feb 2002 23:18:59 +0100
From:      Cliff Sarginson <csfbsd@raggedclown.net>
To:        questions@freebsd.org
Subject:   Re: BASH programming question
Message-ID:  <20020220221859.GA2006@raggedclown.net>
In-Reply-To: <5.1.0.14.2.20020220160637.02763050@pop.earthlink.net>
References:  <5.1.0.14.2.20020220160637.02763050@pop.earthlink.net>

next in thread | previous in thread | raw e-mail | index | archive | help
On Wed, Feb 20, 2002 at 04:17:57PM -0500, B.K. DeLong wrote:
> Hey all -
> 
> I'm somewhat new to the world of BASH scripting. I'm trying to write a 
> script that I can throw in cron to check if my IP has changed. However, I'm 
> having problems with the variable. What I'm trying to say, is "if $IP is 
> not null then email me"
> 
> ie. if diff produces no results, then the IP is the same.
> 
> However, I can't quite figure out the way to define this without getting a 
> "too many arguments" error.
> 
> #!/usr/local/bin/bash -x
> ifconfig | grep "inet " | cut -f2 -d" " | grep 24. > /.newip
> IP='diff /.newip /.currentip'

Your quotes are the wrong way around..
You need
`
not
'
And "not equal to" is "!=" and ... "null" , is that built into bash ?
I think not, try "".
Also you should get into the habit of using $ vars in {} to
avoid errors if they have a NULL value, i.e.
${IP}

Also the "cool" way to do this is to actually check the exit code
from diff "$?", if it is zero then no differences were found.

-- 
Regards
   Cliff Sarginson -- <csfbsd@raggedclown.net>

To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-questions" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20020220221859.GA2006>