in reply to Perl CGI Environment Variable

It sounds like the environment under which your process is running doesn't have $ENV{"HOME"} defined (in other words the "HOME" environment variable isn't set). But it's hard to say because you didn't actually bother to explain what "it's not working!" means, so I can only guess. Did you get some error message that might mean something to one of us? Are you running under the "use warnings;" pragma so that if $ENV{"HOME"} is undefined you'll get a warning? That would be helpful.

Update: When I say "It sounds like the environment under which your process is running doesn't have $ENV{"HOME"} defined...", I'm saying that it's probable that your spawned process is running under a different environment instance (ie, as a different user). Thus, even though you think HOME is set, it's not set in the environment under which your job is running. Turning warnings on might tell you that the hash element you're looking for isn't defined. Now you know one possible reason why.


Dave

Replies are listed 'Best First'.
Re: Re: Perl Environment Variable
by sasikumar (Monk) on Jan 30, 2004 at 06:19 UTC
    Hi, Thanks for ur comments The script runs perfectly when i run it from command line. It's able to get those environment variables. I have an another perl script whic is a cron process which would initiate my first script to do some action. In this case its not able to get those environment variables. sasi
      Oh, sure it's working. The Perl program *is* getting the environment variable. However, the variable isn't set. Programs run from cron have hardly any environment variables set. And that makes sense. "HOME" is something associated with a user logged on. A program run from cron isn't started by a user - so there's no "HOME" environment variable.

      You either need to set it explicitely yourself, or you should write your program in such a way you don't need the variable.

      Abigail

        I get around this by writing my crontab as such:
        0 0 * * * ssh yourhost yourscript
        You could also use rsh if you were so inclined. The [r|s]sh in to your local machine creates a login shell, thereby setting the environment to what one might expect.

        thor

      Cron tasks are not shell sessions. You don't have the same environment. Your process has only the barest minimum environment setup, and that doesn't include $ENV{HOME} or other trivial niceties made by your .cshrc / .bashrc or other profile stuff.

      --
      [ e d @ h a l l e y . c c ]