procmail
[Top] [All Lists]

Re: extract number out of body and do condition on it

2001-07-03 12:38:50
Jill asked,

| When a particular mail message comes thru with this in the body:
| 
| 
| Alert        15.222 secs
| 
| I would like to be able to grab the "15" portion - and see if it's
| greater than 40.  If the number is greater than 40 - I would then like
| to send the mail message to someone.

| Can someone help?
| 
| How do I grab the number - compare it to another number - and if A is
| greater than B - mail the message??

| :0
| * ^From(_dot_)someone(_at_)somewhere
| * ^Subject:.Alert Message
| {
|         :0 Bc
|         *Server down alarm|100\.000\%

You don't need to escape a percentage sign.

|         ! someone(_at_)somewhere
|         :0 Ac
|         in-testing

If in-testing is an mbox rather than a directory, you should use a second
colon to get a local lockfile.

| *******EVERYTHING ABOVE WORKS OK*******************
| *******BELOW IS WHERE I NEED HELP*********************
|         :0 Bc
|         * ^Alert \/(\d+)

As Don has explained, \d -- must be a perlism -- is just an ordinary d to
procmail.  I disagree with his advice to run test, though.  Procmail can
handle the numeric comparison itself:

          :0Bc
          * ^Alert +\/[0-9.]+
          * $ $MATCH^0
          * -40^0
          ! that(_at_)other\(_dot_)person

          :0: # no second colon if you're saving to directories
          finalrestingplace
  }

I'm including period in the character class under the assumption that
40.001 counts as greater than 40.  If you want to forward the message
only if the number is 41 or more, leave out the period and MATCH will
grab only digits left of the period, giving you the integer portion.

_______________________________________________
procmail mailing list
procmail(_at_)lists(_dot_)RWTH-Aachen(_dot_)DE
http://MailMan.RWTH-Aachen.DE/mailman/listinfo/procmail