kelcey has asked for the wisdom of the Perl Monks concerning the following question:

Hello All I have a problem, I need to run a script from the cron that ssh other machines arcoss the network. it works great from the command line but when I run it from the cron it fells. The script calls a back up routine(quick restore) and forks a new child process that is exec on the command line. $pid = fork(); if($pid == 0){ exec(qtar -g $path $file -L FULL -R >> $LOGFILE) || warn } I can run this from the command line (as root) with no problems. I think the problem is in ENV. beacuse the back up routine fells when tring to open a remote file. I notice that the cron only have a few ENV listed. I think I need to add more ENV to the cron ???

Replies are listed 'Best First'.
Re: cron and ssh
by chromatic (Archbishop) on Dec 04, 2000 at 00:40 UTC
    exec will never return if the command succeeds. Otherwise, it will return and store the error message in $!. You ought to include this in your warn to aid your debugging:

    exec('qtar', "-g $path $file -L FULL -R >>$LOGFILE") or warn "Couldn't exec: $!";

    If you do need to modify your environment, add and modify keys of the special %ENV hash, like so:

    $ENV{path} .= '/usr/local/myneatprogram/bin'; $ENV{qtar_args} = '-C';
    Those are made-up examples.