M. Lewis wrote:
I'm trying to move the configuration variables out of three perl scripts and put them in a config file. Fine, no problem so far.

The way this works is an email message with a given subject is processed by procmail then passed off to the first perl script. The first script sets up the second. The second sets up the third script.

If at the command line I do './script1.pl < my_email_message.eml everything works fine. The three scripts fire off as they should and do their tasks.

However, if allowed to be processed as normal (started via an incoming email message), then it does not work.

The root of the problem is I read the configuration file in script2.pl thusly:

do './mcr.conf';

The only way I have found thus far to make this work via the 'normal route' of an incoming email message is to change the above line to:

do '/absolute/path/to/mcr.conf';

Which defeats my purpose of getting the configuration items out of the scripts themselves. I don't want the users to have to edit the three scripts, only the mcr.conf file.

Is there a way around this?

Your problem could be one of two things.

1. The procmail is run by the user but not from the directory where mcr.conf is. Without forcing the user to start in this directory, you would have to put the path somewhere in the process; either in the Perl script or perhaps your procmail has an environment variable you can set. In UNIX, you can read the environment via %ENV. You can try:

  do "$ENV{HOME}/path/from/user/home/mcr.conf";

2. The procmail is run when a new message is placed in the user's mailbox. In UNIX, this is done by a daemon with the uid mail. This means it has a completely different environment but it may set some environment variables before calling your script that describe what it is doing and who it is doing it for. In that case:

  my $user = $ENV{PROCMAIL_USER}; # Use the appropriate name
  my $home_dir = glob( "~$user" );
  do "$home_dir/path/from/user/home/mcr.conf";

Note that PROCMAIL_USER is just a guess. Consult the documentation for procmail to get the correct name.

I don't normally work in MS Windows, so I can't help you there but if you're willing to dig deep enough I'm sure you can find the equivalent somewhere the the documentation.

See:
perldoc -f glob
perldoc File::Glob
perldoc perlvar (search for ENV)


--

Just my 0.00000002 million dollars worth,
   --- Shawn

"Probability is now one. Any problems that are left are your own."
   SS Heart of Gold, _The Hitchhiker's Guide to the Galaxy_

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to