Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Determining an Empty File in a script

Status
Not open for further replies.

jpor

Technical User
Nov 29, 2000
212
GB
Hi Gurus,

I am currently developing a script that checks if a file has 0 bytes.

If doesn't then it e-mails. I can do the e-mailing bit. But can someone point me in the direction of how I can check a file for 0 bytes ?

Many thanks in advance.

( "To become Wise, first you must ask Questions")
 
jpor,

I believe find . -size 0 will do the trick.


Thanks,

John
 
Well... find /path/to/file -size 0

Depending on where the file is located.

John
 
Code:
if [ ! -s path2file ] ; then
   echo "file either doesn't exist OR its size is 0"
fi;

vlad
+----------------------------+
| #include<disclaimer.h> |
+----------------------------+
 
Cheers Guys.

How would I manupulate that command in an if statement.

As I will be scanning the file and if it = 0 then not e-mail else e-mail.

Thanks again.




( &quot;To become Wise, first you must ask Questions&quot;)
 
Code:
if [ -s path2file ] ; then
   mailx -s "File is not 0 bytes" name@domain.com
fi
 
Thanks vgersh99. That works a treat.


( &quot;To become Wise, first you must ask Questions&quot;)
 
johngiggs,

you have to negate the test.

vlad
+----------------------------+
| #include<disclaimer.h> |
+----------------------------+
 
Vlad,

It seems as though he only wants to be notified if the file is greter than 0 bytes - "if it = 0 then not e-mail else e-mail".

If that is true, then my post should work fine.

Code:
if [ -s path2file ] ; then
   mailx -s "File is not 0 bytes" name@domain.com
fi

John
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top