in reply to CRON job failing but manual run works

Take a look at Calling System Service command fails in cronjob (posted yesterday) for some issues between running scripts manually and from cron.

You might also check if /usr/local/perl -V produces the same @INC as cron reports.

If none of that helps, please show the exact code you are running manually and what you have in your crontab file.

-- Ken

Replies are listed 'Best First'.
Re^2: CRON job failing but manual run works
by Dranzaz (Sexton) on Aug 15, 2012 at 19:42 UTC

    Below is the outputs:


    [ /]# perl -le 'print for grep {$_ ne q{.}and -d} @INC' /root/perl5/lib/perl5/x86_64-linux-thread-multi /root/perl5/lib/perl5/x86_64-linux-thread-multi /root/perl5/lib/perl5 /usr/lib64/perl5/vendor_perl /usr/share/perl5/vendor_perl /usr/lib64/perl5 /usr/share/perl5

    [ /]# find -name OpenSSH ./root/Net-OpenSSH-0.57/lib/Net/OpenSSH ./root/Net-OpenSSH-0.57/blib/arch/auto/Net/OpenSSH ./root/Net-OpenSSH-0.57/blib/lib/auto/Net/OpenSSH ./root/Net-OpenSSH-0.57/blib/lib/Net/OpenSSH ./root/perl5/lib/perl5/x86_64-linux-thread-multi/auto/Net/OpenSSH ./root/perl5/lib/perl5/Net/OpenSSH

    So it appears that since I run the script manually as "root" (issues on the practice using of the root user aside) it is using a different install of Perl than CRON, correct?


    Would putting the below in the script be a good option or is there a better option?

    BEGIN { push @INC,( ./root/perl5/lib/perl5' ); }
      So it appears that since I run the script manually as "root" (issues on the practice using of the root user aside) it is using a different install of Perl than CRON, correct?
      Use the full path to perl in cron. That's the easiest approach.

      I don't know anything about your system but probably wouldn't advise hacking the perl script itself. Instead, I'd create a shell script for cron to run using the shell script's absolute pathname.

      In that script I'd set up whatever environment variables that cron either doesn't know about or uses some default value that isn't what you want - man 5 crontab should provide that information. One of those environment variables might be PERL5LIB which modifies @INC - see perlrun - ENVIRONMENT.

      The shell script would then run the perl script using the absolute pathname of the perl you want to use. You might want to use command switches such as -Idirectory which modifies @INC - see perlrun - Command Switches.

      -- Ken

      I added the following Line to craontab:

      perl -le 'print for grep {$_ ne q{.}and -d} @INC' > /tmp/croninc.log

      and the following was the output:

      more croninc.log
      /usr/lib64/perl5/vendor_perl
      /usr/share/perl5/vendor_perl
      /usr/lib64/perl5
      /usr/share/perl5