- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Not sending mail when body is empty
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Discussions
Discussions
Forums
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-23-2002 01:09 PM
тАО08-23-2002 01:09 PM
grep "SYSTEM ERROR" /backup/temp/travel.`date +'%b%d'`.lg | mailx -s "Log Errors at Lincoln" root
Is there a way for mailx to not send the mail if the grep returns nothing? I know it will send mail with -s, but I need to know at a quick glance which server it came from. Any suggestions will be appreciated
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-23-2002 01:20 PM
тАО08-23-2002 01:20 PM
Re: Not sending mail when body is empty
Why don't you let the grep create (or not) the file. Then test (-f or -e) for the existence of it and whether it's 0 bytes (-s) or not before sending it to mailx?
Rgds,
Jeff
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-23-2002 01:21 PM
тАО08-23-2002 01:21 PM
Re: Not sending mail when body is empty
Try this:
# grep -q "SYSTEM ERROR" /backup/temp/travel.`date +'%b%d'`.lg || mailx -s "Log Errors at Lincoln" root
Notice the quiet option ('-q') and the double pipe.
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-23-2002 01:25 PM
тАО08-23-2002 01:25 PM
Re: Not sending mail when body is empty
Oh, sorry, you *don't want to send the mail if 'grep' fails to match, so:
# grep -q "SYSTEM ERROR" /backup/temp/travel.`date +'%b%d'`.lg && mailx -s "Log Errors at Lincoln" root
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-23-2002 01:33 PM
тАО08-23-2002 01:33 PM
Re: Not sending mail when body is empty
I tried that and had fun watching my prompt not come back, then had to ctrl-C it twice.
Note: Sometimes I really enjoy HP-UX's attempt at levity.
When I interrupted it first time it came back:
(Interrupt -- one more to kill letter)
Then when I tested just what it would do in the original scenario it responded:
Null message body; hope that's ok
Have a good weekend,
Jeff
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-23-2002 01:54 PM
тАО08-23-2002 01:54 PM
Re: Not sending mail when body is empty
I tried it also and had to interrupt it also. I already have it the way I wrote, but a mail message is sent with
Null message body; hope that's ok
As the text. So, I get a mail message whether I have an error or not. I want a mail message only when grep returns something. Can you post and example of what you were suggesting?
TIA
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-23-2002 02:10 PM
тАО08-23-2002 02:10 PM
Re: Not sending mail when body is empty
OK, its definitely Friday. Try this. It avoides the "dead letter" or "null body":
# grep -q "SYSTEM ERROR" /backup/temp/travel.`date +'%b%d'`.lg && mailx -s "Log Errors at Lincoln" root < /dev/null
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-23-2002 02:41 PM
тАО08-23-2002 02:41 PM
Re: Not sending mail when body is empty
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-23-2002 02:57 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-23-2002 03:46 PM
тАО08-23-2002 03:46 PM
Re: Not sending mail when body is empty
Thanks. With your help, here is what I am going to do.
INFILE=/backup/temp/travel.`date +'%b%d'`.lg
OUTFILE=/tmp/errors.out
grep "SYSTEM ERROR" $MYFILE > $OUTFILE && mailx -s "Log Errors at Lincoln" root < $OUTFILE
This will put the errors in the body of the email. Thanks again
John