Bruce Shaw wrote:
I've got a working dbi script but I can only get it going live.
If I run it as a crontab entry, it won't work because there's no environment variables.
I've even tried something like:
12 23 * * * cd /usr/local/bin/mine; ./setup_vars; set > set.txt; ./myscript.pl & > diag.txt
where setup_vars is a script that's supposed to set my variables. I've also got them set in .profile, but when I examine set.txt, none of the environment variables are there and diag.txt shows that nothing has worked because the variables are missing.
What am I doing wrong?
I've had to run an external command like printenv to get the environment when ENV is missing due to cron or whatever...
Try Something like this:
my %myENV = %ENV; # because we don't want to mess with the real %ENV
if(!%myENV) {
for(`/bin/printenv`) {
chomp;
my($k,$v) = split /=/, $_;
$myENV{$k} = $v; }
}%ENV is pretty unreliable as you've experienced... Perhaps there is a more reliable way to do what you're trying to accomplish?
