mail filter

Hi all:

I have a problem with this simple script. It appears that it should work, but I am getting an error message.

I am trying to pass a file through a filter to grep for "urgent" and forward the message to me.

Here it is.

#!/bin/ksh
#
if (`grep urgent /tmp/test.tmp| wc -l` -gt 0)
then
mailx -s "urgent message" root < /tmp/test.tmp
else
mailx -s "mail forwarded from sysname" tm6858 < /tmp/test.tmp
fi

My error message is this:

root> ./urgent.sh
./urgent.sh[3]: 2: not found

:confused:

I got this message as a response to the program.

What does "not available for sendmail programs" mean?

The original message was received at Thu, 24 Jan 2002 07:28:50 -0600 (CST)
from root@localhost

----- The following addresses had permanent fatal errors -----
"|/root/urgent.sh"
(expanded from: userID)

----- Transcript of session follows -----
sh: urgent.sh not available for sendmail programs
554 "|/root/urgent.sh" ... Service unavailable

Here is my /etc/aliases output.

userID :"|/root/urgent.sh"

:confused:

You set this up as ksh but are using ( ) in your if statement.

Remember to put in the white space.

if [ `grep urgent /tmp/test.tmp| wc -l` -gt 0 ]

Thanks I forgot about the whitespace. That did solve the first problem.

However, I am still getting this error message.

----- The following addresses had permanent fatal errors -----
"|/root/urgent.sh"
(expanded from: tm6858)

----- Transcript of session follows -----
sh: urgent.sh not available for sendmail programs
554 "|/root/urgent.sh" ... Service unavailable

How are you running this? Are you setting this as part of a forward file? (The script by itself will work.)

I have a file in the /tmp directory called /tmp/test.tmp

I mail this file to a user who is aliased in the /etc/aliases file.
tm6858 :"|/root/urgent.sh"

This file is owned by root...
-rwxr-xr-x 1 root sys 196 Jan 24 08:28 urgent.sh

I have this script process the file and forward it to root if it is "urgent" or if not it just sends the file to the user.

What version of Sendmail ?

I tried it and it worked fine after I set up the alias and did the newaliases command (I called the script test2)

/etc/mail/aliases:
hog: "|/tmp/test2"

The only thing I can think of is that Sendmail won't use a script if it's set up as the 'shell' for an account - it will complain if it's not in /etc/shells. See the FAQ on www.sendmail.org.

Here is the version that I have.

lrwxr-xr-x 1 root sys 41 Sep 5 2000 sendmail -> /usr/localcw/opt/sendmail/sendmail.V8.9.3

I keep getting this error message.

Final-Recipient: RFC822; tm6858@sysname.com
X-Actual-Recipient: RFC822; |/root/urgent.sh@sysname.com
Action: failed
Status: 5.5.0
Last-Attempt-Date: Thu, 24 Jan 2002 09:30:08 -0600 (CST)

It's like it is trying to send the mail message to "/root/urgent.sh@sysname.com" as a user who would receive mail?

Does your script have the #!/bin/ksh at the top?

Here is the script (only the names are changed) - same as what you posted:
/tmp/test2

#!/bin/ksh
#
if [ `grep urgent /tmp/test.tmp| wc -l` -gt 0 ]
then
mailx -s "urgent message" root < /tmp/test.tmp
else
mailx -s "mail forwarded from sysname" tghunter < /tmp/test.tmp
fi

I then have the alias hog in my alias file which runs /tmp/test2 when it gets email
hog: "|/tmp/test2"

I send a message to hog this way:
mailx -s"huh" hog < /tmp/test1.tmp

/tmp/test1.tmp contains:
this file has urgent in it

The original message never goes anywhere (because of the script). The script sends the file /tmp/test.tmp. The message I get in root mail is:

# mail
From daemon Thu Jan 24 10:45:47 2002
Date: Thu, 24 Jan 2002 10:45:47 -0500 (EST)
From: daemon
Message-Id: <200201241545.g0OFjlg05262@medusa.tampa.intermedia.com>
To: root
Subject: urgent message
Content-Length: 34

urgent - this is the file to send

The only other thing I can see from these postings is the alias you have.

Is it the correct format?

name: whitespace "|/tmp/script"

Everything looks good to me too.

This error message is strange.

----- Transcript of session follows -----
sh: urgent.sh not available for sendmail programs
554 |/root/urgent.sh... Service unavailable

I will try to see if there are any bugs in my version of Sendmail trying to use filters.

I will let you know...

:frowning: :confused:

This may be it - found on the sendmail.org FAQ -
Q3.34 -- What does "foo not available for sendmail programs" mean?
Date: September 24, 1999
It means that you are using smrsh, the sendmail restricted shell; see Q2.13 for details on this. To fix this problem, you need to create a sym-link from smrsh's directory for restricted programs to the program foo. The default location of this directory for restricted programs is /usr/adm/sm.bin in the Open Source version, but vendor versions differ. For example, RedHat Linux 6.0 uses /etc/smrsh, and Solaris 8 uses /var/adm/sm.bin . If you don't know the directory for your OS, first check the smrsh man page, then if that fails, try:

    % strings /path/to/smrsh | grep ^/

where /path/to/smrsh is the P= argument on the Mprog line in sendmail.cf .
So for example:

    % cd /usr/adm/sm.bin
    % ln -s /usr/bin/vacation

would allow the vacation program to be run from a user's .forward file or an alias which uses the "|program" syntax.
Finally, if you want to disable use of smrsh, remove the FEATURE(`smrsh') line from the .mc file used to build sendmail.cf; see cf/README for details on this.

I still can't get it to work even though I did create the link as suggested.

I have contacted some technical folks in my group.

Will keep you posted.

:slight_smile:

I found my solution.

2 problems.

1) my path was wrong. It should be only the filename in the /etc/aliases file like:

user: "|filename".

2) Also, I had the symlink in the wrong directory. Which I found out was not the /usr/adm/sm.bin that is prescribed for smrsh. Do a man on smrsh for details. Mine is /usr/localcw/bin.

# cd /usr/adm/sm.bin ##or /usr/localcw/bin in my case.
# ln -s /your/script/here . ## yes that is a period to put the link here in the current directory.

After that make sure the file that you are parsing is at least 555 for sendmail to process it. I had mine set to 700 which gave me errors.

Thanks for all the input. I hope this helps someelse in the future!

:cool: :wink: