LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
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 01-23-2014, 03:30 PM   #1
tlegend33
LQ Newbie
 
Registered: Sep 2013
Posts: 20

Rep: Reputation: Disabled
sed multiple lines use in if statement


I have a utility that produces a report which includes the below section:

Code:
 recommended_actions
---------------------
(0 rows)
I want to set a variable for this section:

Code:
ALERT=`sed -e '/recommended_actions/,/(0 rows)/!d' ${LOGFILE}`

echo $ALERT
recommended_actions --------------------- (0 rows)
I then want to send an email if $ALERT equals something else, ie:
Code:
 recommended_actions
---------------------
Replace Disk!
(1 row)
Code:
if [[ ${ALERT} != "recommended_actions --------------------- (0 rows)" ]] ; then
         mail -s "ALERT: ${HOSTNAME} disk monitor" ${DBA} < ${LOGFILE}
fi
With this set up, I receive an email regardless of what $ALERT equals. How can I set this to only send me an email if there's something beneath the "recommended actions" line?

Thanks.
 
Old 01-23-2014, 08:08 PM   #2
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 10,006

Rep: Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191
Try placing set -xv at the top of your script after the initial interpreter line and see what ALERT is being set to and why the test is failing.
 
  


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
sed multiple lines previous line gushnik1 Linux - Software 2 10-09-2013 03:15 AM
sed to change patterns on multiple lines neuroimager Linux - General 4 12-08-2010 11:02 AM
Search multiple lines in sed or vi vijay_babu1981 Linux - Newbie 8 10-30-2009 11:02 AM
SED multiple lines masterdam79 Linux - Newbie 6 10-29-2009 04:25 AM
AWK/SED Multiple pattern matching over multiple lines issue GigerMalmensteen Programming 15 12-03-2006 05:08 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 12:42 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
Open Source Consulting | Domain Registration