LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 06-29-2011, 03:42 AM   #1
kais1
Member
 
Registered: Dec 2008
Posts: 61

Rep: Reputation: 17
Mail only files with contents


Dear all,

RHEL El 5

Am using the below script to send mails as an sql output . but the below script sends the generated file even if it is empty (if there is no outputs generated from the sql command) .
I want to send mail only if the file has some valid outputs. How to do this

{code}
export ORACLE_BASE=/u01/app/oracle
export ORACLE_HOME=/u01/app/oracle/product/11.2.0/dbhome_1

cat <filename.ext> | mail -s "ALERTMEDDB$DATE_SUFFIX" <mailid>

mailx -s "ALERTMEDDB$DATE_SUFFIX" mailid < $tmpdir/ALERTMEDDB$DATE_SUFFIX.log &

{code}


Kai

Last edited by kais1; 06-29-2011 at 04:04 AM.
 
Old 06-29-2011, 03:55 AM   #2
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976
You can check the file size using the stat command:
Code:
[[ $(stat -c %s <filename.ext>) -ne 0 ]] && cat <filename.ext> | mail -s "ALERTMEDDB$DATE_SUFFIX" <mailid>
 
1 members found this post helpful.
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Tool to mail contents of new file when created charu Linux - Newbie 2 11-25-2010 12:44 PM
Editing contents of 8 files at once mmahulo Linux - Newbie 7 12-22-2008 05:07 AM
text files contents jaepi Programming 5 06-18-2008 11:07 AM
Comparing files contents? hhegab Linux - Newbie 3 07-01-2004 01:45 AM
to compare the contents of 2 files MaleWithBrains Linux - Newbie 3 01-27-2004 07:39 PM


All times are GMT -5. The time now is 03:01 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration