I have ported out a shell script to a Perl script. It is done but the dang thing has been wiggin ever since I wrote it (when run from crontab). Runs like a champ from command line. Ok, so its obvious. Something odd with the environment. I tried setting what seems to be the necessities in the BEGIN{} clause but to no avail. The script still didn't run properly from crontab. For completeness sake, the actuall problem is not the script. It is an executable that the script has to system(). The executable needed some oracle db info to run properly. Incidently this was the info I manually set in %ENV. Now, I am resorting to alternate methods of troubleshooting. Obviously the next step in this would be to see what the shell script environment used to run and to mimic that environment. The shell script sourced a global config file which really had a lot of what seemed to be nonsense stuff in it. Anyway, again, for the sake of completeness, I went ahead and decided to bite the bullet and 'source' this file in my perl script. Naturally, there is no actual 'source' type command in Perl so I resorted to searching for assistance here.

This is not a plea for help as much as it is a request for comments. Please look over my code. I would like some feedback to see if I can do anything more efficiently.

BEGIN { use Env; # Ok. This is a test. Lets see if I can import # (source) a shell environment list. my $CRONENV = "/u20/home/gvc/bin/run_cronenv"; open(SOURCE,$CRONENV) or die("Cannot read $CRONENV\n"); while ( <SOURCE> ) { chomp(); $_ =~ s/export //; if ( !/^#/ and /\W/ ) { (my $key, my $value) = split(/=/) if $_; $ENV{$key} = $value; Env::import($key); } } close(SOURCE); # Gotta set some environmental stuff really fast. ## NOTE: this was the stuff I had in here before ## the mimication (tm) of the shell env file above. $ENV{'ORACLE_HOME'} = "/u40/app/oracle/product/8.1.6"; $ENV{'ORACLE_SID'} = "CORPDB"; $ENV{'ORAENV_ASK'} = "NO"; $ENV{'LD_LIBRARY_PATH'} .= $ENV{'ORACLE_HOME'} . "/lib"; # while ( (my $key,my $value) = each %ENV ) { # print "$key=$value\n"; # } } # End BEGIN clause
sidenote: The environment file is used by other shell scripts. It looks similar to this:

# # global environment file # export PATH=/path0:/path1:/path2 export ORAENV_ASK=NO export YADA=YADAYADA export ANOTHER_VAR=something export dt=`date +%y%m%d` # comment here export LAST=blah
The only thing I am mildy concerned about is the $dt environment setting. Does anyone think this will adversely effect my script? I don't think it will but I am still not yet familiar with all those Perl caveats.

TIA guys.

----------
- Jim


In reply to sourcing an external shell file by snafu

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.