Run a program whenever new mail is received

I am working on a program to filter out spam. I'd like the program to be run whenever new mail is received in my public e-mail box, and if it is acceptable, the program forwards it to a private e-mail box. I changed my .forward file to the following:
(the zvikabh is to keep a copy of the e-mail in the public e-mail box, and gigo.out is the filtering program.)
When I receive mail, I get a "returned mail: service unavailable" error e-mail from the mailer. The message contains the following lines:

sh: gigo.out not available for sendmail programs
554 "| gigo.out"... Service unavailable

and gigo.out is not run. Why is this happening?
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

1'st create following entry in /etc/aliases:
zvikabh: "|gigo.out"
2'nd restart sendmail
SlartiAuthor Commented:
I can't accept your answer, because I can't write to /etc/aliases in my system - it's set so that only the sysadmin can modify it. I am looking for a way to do this that will not require any sysadmin priviledges.
>I can't write to /etc/aliases
I'm somewhat confused. How then can your
      "program forwards it to a private e-mail box" ?
If this is possible you may also add what I suggested to your private account.

An other solution would be to call gigo.out peridically by cron.
It then must read your mail database ($MAIL), like:
  mv $MAIL $MAIL.check
  your_filter $MAIL.check >checked
  cat checked >>$MAIL

Become a Certified Penetration Testing Engineer

This CPTE Certified Penetration Testing Engineer course covers everything you need to know about becoming a Certified Penetration Testing Engineer. Career Path: Professional roles include Ethical Hackers, Security Consultants, System Administrators, and Chief Security Officers.

SlartiAuthor Commented:
I forward mail to another account by editing the .forward file in my home directory. For instance, if it contains the line
then all my mail is forwarded to that address.

I cannot accept the crontab suggestion. First of all, it is not the correct approach; I don't have to continuously monitor my mailbox, since it should be possible for the computer to run a job whenever new mail is received. Second, the computer I am using has limitations on the frequency in which users can run crontabs, and I would like high frequency checks.

I am told that this can be done in a fashion similar to the /etc/aliases suggestion, but without sysadmin priviledges.
> I am told that this can be done in a fashion similar to the /etc/aliases suggestion, but without sysadmin priviledges.

Could you please be more specific?
AFAIK, the only solution with sendmail is the one suggested in my 1'st answer.
It's also possible tou use includes in /etc/aliases, but I think that each included file may only contain real user and/or group names, but no programs (I've never tested with programs there).
SlartiAuthor Commented:
>> I am told that this can be done in a fashion similar to the /etc/aliases suggestion, but without sysadmin priviledges.

> Could you please be more specific?

Someone once told me how to do it, but I forgot...

Have you tried a .forward like:


If you are root, in the /etc/aliases: alias: "| the-program you want to run". This also works in your .forward file...

SlartiAuthor Commented:
I tried ahoffman's suggestion and got the same result (service unavailable).
SlartiAuthor Commented:
df: as I said in the comments above, I am not root and would like to solve this problem without contacting the root of my computer. Besides, ahoffmann already suggested exactly the same answer and I rejected it.
Is gigo.out executable, and in sendmail's path?
Have you tried
chomd a+x gigo.out

(or whatever the full path to the file is)

If you ar enot root, then use .forward to pipe the mails incoming to a program. If you only have account and also want ot be able to receive "normal" mail and pass on certain mails to a program, then use .forward to send all incoming mail to procmail, a mail filtering program, that will be able to tell what it should do with different mail from a rulest you write and put in .procmailrc locally on your accnt... i.e. no root interference

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
SlartiAuthor Commented:
Thank you for your answer, it was just what I needed.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Unix OS

From novice to tech pro — start learning today.