Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

simple if-then question

Status
Not open for further replies.

BIS

Technical User
Jun 1, 2001
1,893
NL
Hallo All,

I have the following small shell script:

#!/bin/sh
QMAILINJECT="s"; export QMAILINJECT
sender="$(cat - | 822field From | sed 's/^ *//g')"
seek0 0
exec /var/qmail/bin/qmail-inject -f "$sender" "$DEFAULT"

It takes an outgoing email on my mailserver, fixes an error in the From address (created by a terribly buggy application thankfully hosted on a specific ip) and sends it on.

What I would like now is that if the "$sender" = "uniquename@domain.com" then also have it run through a small awk script (say /etc/test.awk ). How would I insert that statement in the above ?

Any pointers much appreciated.
 
I guess this would work? Hopefully skipping the exec (which I presume is there for efficiency only) shouldn't break the functionality.

Code:
#!/bin/sh
QMAILINJECT="s"; export QMAILINJECT
sender="$(cat - | 822field From | sed 's/^ *//g')"
seek0 0
if [ "$sender" = "uniqname@domain.com" ]
then
    awk -f /etc/test.awk | /var/qmail/bin/qmail-inject -f "$sender" "$DEFAULT"
else
    exec /var/qmail/bin/qmail-inject -f "$sender" "$DEFAULT"
fi

I'm curious about seek0; I presume that's jumping back to the beginning of standard input? Where does utility that come from?


Annihilannic.
 
Thanks Annihilannic,

seek0 is part of fdtools


I will try your example, but I really need something like:

if [ "$sender" = "uniqname@domain.com" ]
then
awk -f /etc/test.awk | /var/qmail/bin/qmail-inject -f "$sender" "$DEFAULT"
AND
exec /var/qmail/bin/qmail-inject -f "$sender" "$DEFAULT"
else
exec /var/qmail/bin/qmail-inject -f "$sender" "$DEFAULT"
fi

Is the AND possible?
 
That shouldn't be necessary, it's already in the awk pipeline.

exec just means "replace the current process with xyz" as opposed to forking a child, but the calling program shouldn't care because whatever value qmail returns will be the final code returned to the calling program. awk will read standard input, and your awk program should echo the modified email to standard output, which will be intern processed by qmail-inject.

Annihilannic.
 
Thanks, that clears it up. As you can tell, shell scripting is not part of my day to day job (I'm a telecom guy)
I will give this a try and report back - your help is very much appreciated.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top