LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   sed multiple lines use in if statement (https://www.linuxquestions.org/questions/linux-newbie-8/sed-multiple-lines-use-in-if-statement-4175492334/)

tlegend33 01-23-2014 03:30 PM

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.

grail 01-23-2014 08:08 PM

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.


All times are GMT -5. The time now is 07:16 PM.