Tell me more ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I have created a cronjob in Unix to execute an .sh file which will send me the output of an Excel file to my mail id once it is executed.

But now I do not want an email if there is a "NO RECORD" or "Zero byte" output in the Excel file.

How do I tackle this issue?

share|improve this question
5  
It is very difficult to answer the question of how you should change it when you have not shown us how it currently operates. (there are multiple approaches you could be using) – Andrew B Feb 4 at 6:09
Are you asking if the file size is not zero? stackoverflow.com/questions/5920333/how-to-check-size-of-a-file – J Moore Feb 4 at 6:52

closed as not a real question by Gilles, Renan, manatwork, jofel, rahmu Feb 5 at 13:40

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, see the FAQ.

1 Answer

I am not sure what you mean by "output of an Excel file". Nevertheless:

Your shell script will most probably output text to STDOUT. cron then collects this text and sends it as mail, whenever there was some output.

You can explicitly send your output to a temporary file. Check whether it contains some text and output it to STDOUT otherwise.

If I understood your situation correctly, something like this should do:

tmp=$(mktemp)
(yourcommand) > $tmp
grep -qe "NO RECORD" -e "Zero byte" $tmp || cat $tmp
rm $tmp
share|improve this answer
Or maybe just test -s $tmp if you want to check whether the output file is non-empty. – tripleee Feb 4 at 9:25

Not the answer you're looking for? Browse other questions tagged or ask your own question.