controlled environment for regular expressions?

David Benfell benfell at parts-unknown.org
Tue Sep 2 06:17:28 UTC 2014


On Mon, Sep 01, 2014 at 03:38:13PM -0600, Warren Block wrote:
> On Mon, 1 Sep 2014, David Benfell wrote:
> 
> > Hi all,
> >
> > I am having a major problem with regular expression matching returning
> > different results when run from a script under cron or as a delivery
> > instruction from postfix rather than from the command line.
> >
> > I don't even know how to debug this. These are all in scripts and
> > delivery instructions that I have had working for over a decade. And
> > when I run them from the command line, they work as expected.
> >
> > The path for seeking executables should not be at issue. I use the
> > PATH variable in my crontabs and set it to the same PATH as at a
> > terminal.
> >
> > I have encountered this problem with both grep and GNU sed (gsed, from
> > the port).
> >
> > This is all stuff that worked until recently, and worked for years
> > under Linux. The only change I think I've made is to implement an IPv6
> > tunnel. I hope, really hope, I can safely say that's irrelevant.
> >
> > I use zsh, also a choice that's over a decade old, for both my command
> > line and to run scripts.
> >
> > I've never liked regular expressions. I think they are an awful
> > kludge. But unfortunately, a major part of my workflow depends on them
> > working correctly and *predictably*.
> >
> > Has anyone else encountered problems with this? How do you fix it?
> 
> An example would be useful.  My first guess is that the regexes are 
> working, but some invisible whitespace like carriage returns has snuck 
> into the values.

I've been pondering how to respond to this. It's all deeply buried in
how I sort email, which is with my own mail delivery agent written in
perl.

The MDA provides the option to call an external program, in this case,
grep, and sort or not sort a message into the associated Maildir based
on the exit code.

One of these instances is where I search the email headers with:

/usr/bin/grep "^Subject: Cron"'

From the command line, it matches every time on this header:

Subject: Cron <benfell at home> /usr/local/bin/pycardsyncer

and properly sorts the message.

But when this MDA is called either from a cron job or with postfix's
delivery instruction, it now fails every time.

I haven't modified this MDA in a while. I wrote it years ago. The last
change I made to the delivery script was in 2011. I've been using it
continuously for probably over a decade.

Thanks!
-- 
David Benfell <benfell at parts-unknown.org>
See https://parts-unknown.org/node/2 if you don't understand the
attachment.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 819 bytes
Desc: not available
URL: <http://lists.freebsd.org/pipermail/freebsd-questions/attachments/20140901/d47b439c/attachment.sig>


More information about the freebsd-questions mailing list