Redirecting email to a Script

Andrews Carl 448 Carl.Andrews at CRACKERBARREL.COM
Thu May 12 20:28:16 IST 2005


    [ The following text is in the "iso-8859-1" character set. ]
    [ Your display is set for the "US-ASCII" character set.  ]
    [ Some characters may be displayed incorrectly. ]


You log file shows sendmail is trying to use "|/post_leads_to_sugar".


I have a working script in place, it does not do anything useful but
maybe this will help:


Email address: blockme at mail.crackerbarrel.com 
Script: /sbin/spamtest



ls -lia /etc/smrsh/spamtest:
99990 lrwxrwxrwx    1 root     root           14 Oct 23  2003 spamtest ->
/sbin/spamtest

grep spamtest /etc/aliases:
blockme:        "|/sbin/spamtest"


Email to blockme at mail.crackerbarrel.com is passed to /sbin/spamtest
script:
#!/bin/sh
###############################################################################
#######################
# Create 02.01.2002???? - CDA to check for SPAMMers/Open Relays of
incoming mail
# Returns:
#    10.06.2003.cda - setup so that it can read headers emailed to it and
block ip address of mailserver
#               <NEVER IMPLEMENTED>
###############################################################################
#######################


###############################################################################
#######################
# Read stdin and look for the last mailserver's IP address
###############################################################################
#######################
echo "BEGINNING!" >> /tmp/spamtest.log
Block=1
while read mydata; do
        echo " .... READING " >> /tmp/spamtest.log
        emailserverIP=`echo ${mydata} | grep ^Rec | grep [[]`
        if [ -n "$emailserverIP"  ];then
                mailserver=`echo $emailserverIP | cut -f 2 -d '[' | cut
-f1 -d ']'`
                Block=1
               
#######################################################################
               
#######################################################################
                if [ "`egrep -i $mailserver /etc/mail/GoodSpammers`" ];
then
                        Block=0
                fi

               
#######################################################################
               
#######################################################################
                if [ "`egrep -i $mailserver /etc/mail/KnownSpammers`" ];
then
                        Block=0
                fi

                if [ ${Block}   == 1 ]; then
                           # This is where we need to modify rules to
block from "spammer", but for now just send me an email

                           # and do nothing else.
                        echo "Block Me: ${mailserver}" | mail
candrews at crackerbarrel.com
                fi
        fi
done
echo "FINISHED" >> /tmp/spamtest.log



grep blockme /var/log/maillog:
May 12 14:17:37 mail sendmail[14415]: j4CJHWwo014414:
to="|/sbin/spamtest", ctladdr=<blockme at mail.crackerbarrel.com> (8/0),
delay=00:00:05, xdelay=00:00:05, mailer=prog, pri=34014, dsn=2.0.0,
stat=Sent


Hope this helps,

Carl


-----Original Message-----
From: MailScanner mailing list [mailto:MAILSCANNER at JISCMAIL.AC.UK]On
Behalf Of David C.M. Weber
Sent: Thursday, May 12, 2005 12:57 PM
To: MAILSCANNER at JISCMAIL.AC.UK
Subject: Redirecting email to a Script


Brief overview:
        Mailscanner system in front of an exchange server.  I'm trying
to get email to activate a script via an alias when an email comes in.


Right now I've got /etc/aliases set up w/:

somebody:          "| /post_leads"

Then I did a newaliases.



I have a symbolic link in /etc/smrsh pointing to the real script.
Here's a ls -lah

[root at computername smrsh]# ls -lah
total 12K
drwxr-xr-x   3 root root 4.0K May 12 13:36 .
drwxr-xr-x  57 root root 4.0K May 12 13:42 ..
lrwxrwxrwx   1 root root   35 May 12 13:36 post_leads ->
/nobody_scripts/post_leads


The nobody_scripts is a temp directory w/ bad permissions (777), but I
just want to get it working. ls -lah:

[root at computername nobody_scripts]# ls -lah
total 12K
drwxrwxrwx   2 root root 4.0K May 12 13:36 .
drwxr-xr-x  22 root root 4.0K May 12 13:36 ..
-rwxrwxrwx   1 root root    0 May 12 13:28 out.txt
-rwxrwxrwx   1 root root   32 May 12 13:29 post_leads



And finally, here's the script:
#/bin/bash
echo $1 >> out.txt





More information about the MailScanner mailing list