Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

CRON job failing but manual run works

by Dranzaz (Sexton)
on Aug 15, 2012 at 17:37 UTC ( #987603=perlquestion: print w/ replies, xml ) Need Help??
Dranzaz has asked for the wisdom of the Perl Monks concerning the following question:

Hello,

Recently I have had to update a router interface speed check script to work with the newer Cisco CRS routers that run XR instead of IOS. The only way I could get the script to connect to the routers at all was to utilize the Nett::OpenSHH module. Unfortunately it was not available via "yum update". Instead I downloaded the compressed file and manually installed (MAKE) the Module.

I can manually run the script without issuse or error. However, when the cronjob attempted to run it spits out and error (see below). I searched this site and others and the only recommendation I have found so far was to ensure "perl -mcpan" (?) showed is as properly installed. If have done this and it claimed that the module it "up to date".

Can anyone assist in getting this module to be recognized when cron is attempting to run the script.

Relevant Inforamtion:
=================================================
<removed> ~# uname -a
Linux <removed> 2.6.41.4-1.fc15.x86_64 #1 SMP Tue Nov 29 11:53:48 UTC 2011 x86_64 x86_64 x86_64 GNU/Linux
<removed> ~#
=================================================

=================================================
CRON Error:

Can't locate Net/OpenSSH.pm in @INC (@INC contains: /usr/local/lib64/perl5 /usr/local/share/perl5 /usr/lib64/perl5/vendor_perl /usr/share/perl5/vendor_perl /usr/lib64/perl5 /usr/share/perl5 .)
at /root/scripts/weathermap_check.pl line 8.
BEGIN failed--compilation aborted at /root/scripts/weathermap_check.pl line 8.
=================================================

=================================================
Begining of code and call:
#!/usr/local/perl -w #set modules to use use Net::Ping; use Net::SSH::Perl; use Net::OpenSSH; use Net::SMTP; use DBI; $ENV{'MYSQL_UNIX_PORT'} = '/tmp/mysql.sock'; $ssh = Net::OpenSSH->new("$hostnames[$testcount]", user => $username, +password => $password, master_stderr_discard => 1) || warn("\$!\n"); $out = $ssh -> capture ("show interfaces $interface[$routercom] | incl +ude BW"); print LOGONE $out; close (LOGONE);
=================================================


UPDATE: The issue has been resolved by copying the OpenSSH.pm file and its associated folder from the suers perl directory into the system perl installation. Thanks to everyone for their assistance. As always the monks here rule.

Comment on CRON job failing but manual run works
Download Code
Re: CRON job failing but manual run works
by kcott (Abbot) on Aug 15, 2012 at 18:05 UTC

    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

      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' ); }

        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

        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

Re: CRON job failing but manual run works
by aitap (Deacon) on Aug 15, 2012 at 19:05 UTC
    Are you using local::lib? You may need to source the ~/.bashrc (or some of the last lines of it) of the user who have installed the modules before running your script.
    Sorry if my advice was wrong.
Re: CRON job failing but manual run works
by pvaldes (Chaplain) on Aug 15, 2012 at 20:14 UTC

    mkdir Net and copy or link OpenSSH.pm to the dir /usr/share/perl/5.XX/Net and try again. It's a bad solution but could solve the problem temporally.

    Nett::OpenSHH module. Unfortunately it was not available via "yum update"...

    ok I see....

    Your problem is that this module is misspelled. The ubuntu packages that you need are probably:

    apt-get install libnet-openssh-compat-perl libnet-openssh-perl
      The mispelling was a typo when I was making the post not when I was using "yum".

      Proof: Just did this the following:

      # yum install perl-Net-OpenSSH
      Setting up Install Process
      No package perl-Net-OpenSSH available.
      Error: Nothing to do
      # yum install perl-net-openssh
      Setting up Install Process
      No package perl-net-openssh available.
      Error: Nothing to do

      Also, this is not an Ubuntu install. It is a Fedora Core15. Please see the "uname -a" output above.

      I did however follow your suggestion on linking/copying the .pm file. I also had to create the OpenSSH directory as ther is a dependant "Constants.pm" file that is also needed. I have updated the crontab and am awaiting the results. I did not get an immediate failure message and while watching the "top" output I am seeing both "perl" and "ssh" populating the list. This is a good sign from past experience with this script. I will update as I have information.

        UPDATE: The issue has been resolved by copying the OpenSSH.pm file and its associated folder from the suers perl directory into the system perl installation. Thanks to everyone for their assistance. As always the monks here rule.

Re: CRON job failing but manual run works
by pvaldes (Chaplain) on Aug 16, 2012 at 13:57 UTC

    Fedora, ok, sorry, I miss this part

    You could consider then to download the debian package to your computer and convert to .rpm before to pass your package to yum

    bash$ apt-get install alien; bash$ alien -r /my/downloads/libnet-daemon-perl_0.48-1_all.deb -> libnet-daemon-perl-0.48-2.noarch.rpm generated

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://987603]
Approved by kcott
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (3)
As of 2014-08-31 04:21 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (294 votes), past polls