0

Trying to design a system that can filter incoming email messages from a syslog server. Need to drop if they appear to be duplicates (throttle them). Procmail pipes them to a perl script for processing. That's all working, except if I get a flurry of emails all at once, postfix seems to spawn multiple instances of the piped script. Obviously this is desirable in most cases, but for this project, I have to be able to process the incoming messages one at a time so that a database field can be updated with a timestamp so that subsequent messages that match a criteria can be dropped instead of forwarded to the recipients. **Is there a way to "queue" these incoming messages to be processed one at a time, instead of in parallel? Thanks.

2
  • 1
    Where do you want to do the queueing? You could set Postfix to only deliver one message at a time, or you could do a little magic in procmail. Which you'd choose depends on the results you are after. So, which will it be? Commented May 26, 2017 at 15:59
  • This is not high volume. I think I'll look into the procmail lock file idea first. Thanks. Commented May 26, 2017 at 20:59

2 Answers 2

1

You may use procmail's locking to make multiple instances execute one instance of the perl script at given time. See man procmailrc and man procmailex

:0 w: script.lock
| /.../script.pl

O course there are other ways but How many messages per hour do you expect to process in peak and average hour?

2
  • The last sentence of this answer really should have been a comment on the question. It does however not detract from the validity of the answer itself. Commented May 26, 2017 at 21:02
  • @MichaelKjörling I see it as a hint to someone wishing another solution. Commented May 27, 2017 at 20:30
1

To add to the solution by Andrzej, you can set a lock for a wider region than just a single recipe if you need to with the LOCKFILE special variable.

# Only one instance of Procmail can enter this region
LOCKFILE=.procmail-critical-region.lock

:0
* condition
| action

value=`program`

:0
* another condition
| another action

# We are done now; okay for another instance to enter
LOCKFILE=

In principle, you could have multiple critical sections which are guarded by the same lock file, though I am hard pressed to think of a scenario where this would actually be useful.

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.