Operating System - HP-UX
1827811 Members
1865 Online
109969 Solutions
New Discussion

testing a file then emailing it ..

 
SOLVED
Go to solution
someone_4
Honored Contributor

testing a file then emailing it ..

I need a script or command line to look at a file and if it has data in it to email it ..
If no data in it .. not to email it.
I tried test -s filename
but it didnt work.

Thanks

Richard
4 REPLIES 4
A. Clay Stephenson
Acclaimed Contributor
Solution

Re: testing a file then emailing it ..

Hi Richard,

Your test -s filename should have been fine.
Did it look something like this:

if [ -s filename ]
then
echo "Non-zero filesize"
else
echo "Empty File; skipping"
fi

If by no data then you mean if all I see are blanks or LF's or CR's, that's a bit different.

Clay
If it ain't broke, I can fix that.
Joseph C. Denman
Honored Contributor

Re: testing a file then emailing it ..

hmmm... -s should work

if [ -s $file ]
then
#email me
else
#file is empty don't email
fi

...jcd...
If I had only read the instructions first??
James R. Ferguson
Acclaimed Contributor

Re: testing a file then emailing it ..

Hi Richard:

This works. Compose an empty file, try this, and then echo something to it with redirection:

if [ -s /tmp/myfile ]
then
echo "file has data"
else
echo "file is empty!"
fi

You could also do:

if (( `wc -c < /tmp/me` > 0 ))
then
echo "there is data!"
else
echo "this file is empty"
fi

Regards!

...JRF...
Satish Y
Trusted Contributor

Re: testing a file then emailing it ..

Hi Richard,

-s should work....

You can also do like this:

siz1=`wc -l myfile`

if [ $siz1 -eq 0 ]
then
#dont mail
else
#mail
fi

This will work definitely....

Cheers...
Satish.
Difference between good and the best is only a little effort