in reply to How was my script ran?

Okay, I'm replying to my own post because I've thought of one way to do this... but it's still not 100% satisfactory for what we need right now... So I want to eliminate it from the discussion before it's suggested.

One thing I could do is make alias links for the program:

$ ln -s actual-script.pl mail-version
$ ln -s actual-script.pl cgi-version
etc.

and then just check $0. But that's still not very portable (perhaps portability for a script like this is too much to ask ;-)

Replies are listed 'Best First'.
Re: Re: How was my script ran?
by jasonk (Parson) on Mar 05, 2003 at 00:55 UTC

    This and the ENV methods are probably about as portable as you are going to get, if you want total, complete portability under all circumstances, you will likely have to pass the version as an argument.

      Okay, follow-up question: Is there someplace I could find out what ENV keys I should be expecting in general with these things? I mean, I would assume $ENV{"SENDER"} is probably pretty universal among MTAs/MDAs calling a perl script, but others seem pretty OS/MTA/MDA/webserver specific and I would like to avoid using those ;-)

        Wouldn't it be a bit simpler to pass a caller-id parameter into the script?

        perl -s yourscript -C=cgi ..other params...

        perl -s yourscript -C=mta ..other params...

        perl -s yourscript -C=cli ..other params...

        Is there someplace I could find out what ENV keys I should be expecting in general...

        Well, do you have access to each of the systems where this script is expected to run? If so, just run this command line on each system:

        perl -e 'print map { "$_ = $ENV{$_}\n" } sort keys %ENV'
        Another reply below has already mentioned %ENV keys that are specific to CGI, and any one of these should be common across systems...