Solved

Bash script with OR statement

Posted on 2007-04-10
3
4,270 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 125 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

Application Discovery Service in AWS

In the era of the cloud, customers migrating away from their existing on-premise infrastructure. This requires lots of planning, strategies, and effort to identify their existing resources and determine how best to migrate.  Datacenter migrations happen in four phases -

Question has a verified solution.

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

Introduction We as admins face situation where we need to redirect websites to another. This may be required as a part of an upgrade keeping the old URL but website should be served from new URL. This document would brief you on different ways ca…
Join Greg Farro and Ethan Banks from Packet Pushers (http://packetpushers.net/podcast/podcasts/pq-show-93-smart-network-monitoring-paessler-sponsored/) and Greg Ross from Paessler (https://www.paessler.com/prtg) for a discussion about smart network …
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:
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

617 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