Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Bash script with OR statement

Posted on 2007-04-10
3
Medium Priority
?
4,273 Views
Last Modified: 2013-12-16
I am trying to write an OR statement in the nested IF statement that will look for various user emails.  My question here is, is there a more efficient way?  Also, does the statement look ok?

Here is what i have, i did not write the original script, i just expanded on it:

#!/bin/sh
SM="/usr/sbin/sendmail -i"

cd /var/spool/filter
trap "rm -f out.$$" 0 1 2 3 15
cat | /usr/bin/spamc > out.$$
if egrep -q "X-Spam-Flag: YES" < out.$$
then
    if [egrep -q "a.tester@test.com" < out.$$] || [egrep -q "b.tester@test,com" < out.$$]
    then
        $SM "$@" < out.$$
    else
        $SM quarantine@test.com < out.$$
    fi
else
        $SM "$@" < out.$$
fi
exit $?
0
Comment
Question by:Brent
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 48

Accepted Solution

by:
Tintin earned 500 total points
ID: 18885706
I'd write it as:

#!/bin/sh

SM="/usr/sbin/sendmail -i"
TEMP=/tmp/out.$$
trap "rm -f $TEMP" 0 1 2 3 15

cat | /usr/bin/spamc >$TEMP

if egrep -q "X-Spam-Flag: YES" $TEMP
then
    if egrep -q "a.tester@test.com|b.tester@test.com" $TEMP
    then
        $SM "$@" <$TEMP
    else
        $SM quarantine@test.com <$TEMP
    fi
else
    $SM "$@" <$TEMP
fi


Note that to test multiple patterns with egrep, you use the '|' sign, which means OR.
0
 
LVL 8

Author Comment

by:Brent
ID: 18885829
ahh i was wondering about the | vs || one was noted as bolean and the other as logic (?).

I like that better than running egrep multiple times.  I will leave this open till tomorrow just incase anyone else has some input.
0
 
LVL 8

Author Comment

by:Brent
ID: 18889533
Looks good, thanks for your help!
0

Featured Post

10 Questions to Ask when Buying Backup Software

Choosing the right backup solution for your organization can be a daunting task. To make the selection process easier, ask solution providers these 10 key questions.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In the first part of this tutorial we will cover the prerequisites for installing SQL Server vNext on Linux.
In part one, we reviewed the prerequisites required for installing SQL Server vNext. In this part we will explore how to install Microsoft's SQL Server on Ubuntu 16.04.
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
Suggested Courses

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question