File contents required for emailing.

I have created three SQL scripts that are run by one central script. What I need to do is verify the output file from the three SQL scripts(KSH Scripts) is worth emailing. This I would like to do by verifiying the contents of the result file.

The contrlooing script creates the result file then the SQL scripts append to it from then on until the opreation completes.

For instance I have ecohed a line for each instance of the SQL script being run into the result file. So there are three lines minimum in the result file, what I would like to do is count the lines if ther are more that three line email the file, if ther are less just delete the file.

I am having trouble assinging a varialbe to the lines counted in the result file.

I have tried;

wc -l result_file
let line_c=$a-$b
if [ lin_c -le 3 ]; then
Email file
else
delete file
fi

HELP!!!!!

I don't know what $a and $b should be, but I think I see what you want to do...
You want to email the file out if it's less than or equal to 3 lines long, and delete it otherwise... right?

for ksh, something like this should work:

#! /bin/ksh

fil_len=$(wc -l < result_file)
(( fil_len <= 3 )) && {
   mail_the_file_here
   } || {
   otherwise_delete_it
   }

Excellent, it worked.

I had to adjust the final code a little, but the result is exactly what I was trying to do.

Thank you very much.

The result was not correct I have had to adjust the code to get the correct response but am unable to.

fil_len=`wc -l < input_file`
if [ fil_len > 3 ]; then
email file
elif [ file_len < 3 ]; then
delete empty file
fi

The test statement will not accept the value from fil_len, I have output to the screen to see if it is valid and it gives a number but not sure if it is char or numeric.
The output looks like this;
9

No matter what I do it will only select the first part of the statement as true. Regardless of the lines in the file.
All in a Korn Shell (KSH)

sorry for the premature elation!!!! (hair trigger trouble you know)

If it's in braces "[", and not double-perens "((", you'll need to use the "$" character:

...
if [ $fil_len > 3 ]; then
...

Does that help?

The only thing I had not tried was the

if ((fil_len > 3)) then

I had Tried

if [ $fil_len > 3 ]; then

if [ "$fil_len" > 3 ]; then

if [ "$fil_len" > "3" ]; then

if [ "fil_len" > 3 ]; then

just about every permutation you could thing of......... except

if ((fil_len > 3)) then

Which works successfully (tested fully I might add)

Thanks again for the insight how to resolve this one.

To do numeric tests in either a bracket or double bracket form of if statement, you must use -gt like this...

if [ $fil_len -gt 3 ] ; then

When you use > in that style of if statement you are testing which string comes first in straight ascii sort.