Aaron Optimizer Digulla <dia(_at_)unix(_dot_)swx(_dot_)com> writes:
As sysadmin, I get a lot of "status" mails (the system X is
ok, etc). Example:
Filesystem kbytes used avail capacity Mounted on
/dev/vx/dsk/data1/sybdumps 14399925 7742124 5217809 60%
/export/dat/sybdumps
...
I want to get this mail only when the available blocks go below
100MB. If the available blocks are above 100MB, the mail
should be saved in some folder (for statistics).
I can write a filter in awk, perl or python but what should
the condition look like ?
Well, first you need to extract the availible blocks from the message
using the \/ token:
* B ?? ^Filesystem.*$[^ ]+[ ]+[0-9]+[ ]+\/[0-9]+
Then, you need to compare the value in MATCH to 102400. This can be done
using procmail's scoring ability. You need to do variable substitution
to get that value in the MATCH variable into the condition:
* $ $MATCH^0
* -102400^0
The first of those adds the of the number in the MATCH variable to the
score and the second substracts 102400 from the score. The recipe will
only succeed if the final score is positive, so that's all you need.
# Identify these messages and perform the extraction. You may
# want to add a match on the Subject: or From: header to more
# conclusively identify these messages.
:0
* B ?? ^Filesystem.*$[^ ]+[ ]+[0-9]+[ ]+\/[0-9]+
{
# Always save the message to the folder for statistics
:0 c:
some-folder-here
# Are we done? Only if the free space is greater than
# 102400K. Also pass the message through if the previous
# recipe (the save to folder) failed (no free space!?!?)
:0 a
* $ $MATCH^0
* -102400^0
/dev/null
}
Philip Guenther