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.
>
Well first, you can test the exit value of diff to see if there
were differences:
if diff /var/cache/IP/1 /var/cache/IP/2; then
#commands for when files are the same
else
#commands for when files differ
fi
Or if you only care when they differ:
if ! diff /var/cache/IP/1 /var/cache/IP/2; then
#commands for when files differ
fi
If you really need to test for empty files, try:
if [ -s filename ]; then
#commands for when file is *not* empty
else
#commands for when file is empty
fi
Or if you only care for the empty ones:
if [ ! -s filename ]; then
#commands for when the file is empty
fi
-Kyle
--
_
-------------------------------ooO( )Ooo-------------------------------
Kyle J. McDonald (o o) Systems Support Engineer
Sun Microsystems Inc. |||||
Enterprise Server Products [EMAIL PROTECTED]
1 Network Drive BUR03-4630 \\\// voice: (781) 442-2184
Burlington, MA 01803 (o o) fax: (781) 442-1542
-------------------------------ooO(_)Ooo-------------------------------
Want to buy your Pack or Services from MandrakeSoft?
Go to http://www.mandrakestore.com