LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Enterprise Linux Forums > Linux - Enterprise
User Name
Password
Linux - Enterprise This forum is for all items relating to using Linux in the Enterprise.

Notices


Reply
  Search this Thread
Old 10-19-2016, 05:38 AM   #1
jponnusamy
LQ Newbie
 
Registered: Oct 2015
Posts: 9

Rep: Reputation: Disabled
Shell Script sending "Null message body; hope that's ok"


Hi,
I am not much familer with Shell Scripting. As per requirement we want to monitor Logs and send Alert if specified Error present in the Log. I got below code from some social Network.
The Problem is it's Sending "Null message body; hope that's ok" Message if there is no Errors on the File. We set it in Cronjob, So every 30minutes I am getting Empty Body Mail. We want to ignore null body message. So, Kindly please help on this.


Code:
#!/bin/bash

string='ORA-01591'
pathloc='/opt/apps/shared/opentext/vcm/logs/VgnVCM1-runtime.log'

len=${#string}
if [ ! -e DBErrors ] ; then
                grep $string $pathloc > DBErrors
                mail -s "ORA-01591: lock held by in-doubt distributed transaction Error" Jayaram.Ponnusamy@gmail.com < DBErrors

else

if [ ! -e $string ] ; then
                comm -23 <(grep $string $pathloc) DBErrors | mail -s "ORA-01591: lock held by in-doubt distributed transaction Error" Jayaram.Ponnusamy@gmail.com

fi

               grep $string $pathloc > DBErrors
fi
Thanks
 
Old 10-19-2016, 06:52 AM   #2
smallpond
Senior Member
 
Registered: Feb 2011
Location: Massachusetts, USA
Distribution: Fedora
Posts: 4,157

Rep: Reputation: 1266Reputation: 1266Reputation: 1266Reputation: 1266Reputation: 1266Reputation: 1266Reputation: 1266Reputation: 1266Reputation: 1266
The -e tests if a file exists. Use -s to test that it exists and has non-zero size. Using -e on $string seems wrong to me.
 
Old 10-20-2016, 12:17 AM   #3
jponnusamy
LQ Newbie
 
Registered: Oct 2015
Posts: 9

Original Poster
Rep: Reputation: Disabled
Hi,
Thanks for Reply, I tried with -s but that also sending "Null message body; hope that's ok" Mail.
 
Old 10-23-2016, 12:14 AM   #4
AnanthaP
Member
 
Registered: Jul 2004
Location: Chennai, India
Posts: 952

Rep: Reputation: 217Reputation: 217Reputation: 217
Just before sending the mail you want to exclude lines having Null message body; hope that's ok right?

Well one more grep with the -v option that reverses the sense of the search should do it.

OK

PS:
The question is, if the file DBErrors is not going to be used by any other programme, you could apply the grep -v before you write into DBErros.

Likewise for the input of "comm -23" command.

OK

Last edited by AnanthaP; 10-23-2016 at 12:26 AM.
 
Old 10-23-2016, 05:51 AM   #5
jponnusamy
LQ Newbie
 
Registered: Oct 2015
Posts: 9

Original Poster
Rep: Reputation: Disabled
Thanks Anantha for the reply,

I fixed this issue by adding -E option in the Mail command to ignore empty body message.

Thanks
Jayaram
 
  


Reply



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
[SOLVED] Shell script to cause wifi scan get "unexpected end of file" message Ed1952 Linux - Software 5 11-27-2015 09:39 AM
[SOLVED] Errors executing shell script: "command not found" and "no such file or directory" eko000 Linux - Newbie 1 01-14-2011 07:54 AM
Shell script: I have string "abc____def____ghi", how to make "abc def ghi" vouser Programming 8 03-09-2010 10:01 PM
I've got a message about "/dev/null: access denied" Saulo SUSE / openSUSE 2 04-14-2006 10:37 AM
What is "Error sending message, child exited 67 (User unknown.)."? using mutt jonathanztaub Linux - General 0 05-17-2004 09:04 AM

LinuxQuestions.org > Forums > Enterprise Linux Forums > Linux - Enterprise

All times are GMT -5. The time now is 07:28 AM.

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
Open Source Consulting | Domain Registration