redirect - redirecting email text from procmail into bash script -
i trying redirect emails match particular pattern shell script create files containing texts, datestamped filenames.
first, here routine .procmailrc hands emails off script:
:0c: * subject: ^ingest_q.* | /home/myname/procmail/process
and here script 'process':
#!/bin/bash date=`date +%f_%n` file=/home/myname/procmail/${date}_email.txt while read line echo "$line" 1>>"$file"; done
i have gotten frustrated because can pipe text script on command line , works fine:
mybox-248: echo 'foo' | process mybox-249: ls 2013-07-31_856743000_email.txt process
the file contains word 'foo.'
i have been trying email text output date-stamped file hours now, , nothing has worked.
(i've turned logging on in .procmailrc , isn't working either -- i'm not trying ask second question mentioning that, wondering if might provide hint might doing wrong ...).
thanks,
gb
quoting attempt:
:0c: * subject: ^ingest_q.* | /home/myname/procmail/process
the regex wrong, ^
matches @ beginning of line, cannot occur after subject:
. try instead.
:0c:process.lock * ^subject: ingest_q | /home/myname/procmail/process
i specified named lockfile; not believe procmail can infer lock file name script name. might have multiple email messages being delivered @ same time, , don't want logging intermingled in log file, using lock file required here.
finally, trailing .*
in regex redundant, removed it.
(the olde procmail mini-faq addresses both of these issues.)
i realize recipe quick test before start on bigger, entire recipe invoking process
script can replaced like
maildir=/home/myname/procmail date=`date +%f_%n` :0c: ${date}_email.txt
this generate berkeley mbox format, i.e. each message should have from_
pseudo-header before real headers; if not sure whether case, should use procmail -yf-
make sure make (otherwise there no way tell 1 message ends , begins; applies both original solution, , replacement).
because procmail sees file name delivering to, can infer lockfile name now, minor bonus.
using maildir
specify directory conventional way this, can specify complete path mbox file if prefer, of course.
Comments
Post a Comment