On Wed, 27 Feb 2002, Tom Badran wrote:

> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> How can i use an if in a bash script so that it will only run commands if the
> specified file is empty?
>
> Basically, ive set up a cache system by which the output of ifconfig is
> stored in /var/cache/IP/1
>
> Then, every minute my script is run. It first puts the output of ifconfig in
> /var/cache/IP/2 and diff's it with 1 outputing that to a file 'diff'. I then
> want to run a series of commands if the file diff is not empty.
>
> What im trying to do is get an email sent to me every time the IP changes on
> a specific machine, so i always have a record of it for logging in via ssh.
> The specific connection is ppp0 which auto redials on disconnect. If there is
> an easier way of doing this please share with me.
>
The only problem I see with using the raw output from ifconfig is that
the RX and TX fields will always be different. If you were to parse the
output of ifconfig to return only the IP address before writing it to
the file, you could then just compare the current IP against a 'cat' of
the old IP.

I.e.
  IP=`ifconfig eth0|grep "inet addr"|cut -d: -f2|cut -d' ' -f1`
    (or something equally ugly)

  Then do something like:

  Old_IP=`cat $FILENAME`

  [ "$IP" == "$OLD_IP" ]; then do_something


Want to buy your Pack or Services from MandrakeSoft? 
Go to http://www.mandrakestore.com

Reply via email to