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

Goodmorning mighty monks of wisdom ...

Im pritty new to perl but have been able to put together a script using Net::Perl::SSH to authenticate with RSA/DSA keys to get some systeminfo from my linux servers at work. I push this information into a mysql database for web retrival with PHP. The script works great when I run it standalone at bash prompt, but as soon as I put it into cron to run every hour I get permission denied on the '$ssh->login($user)' row in the script. My guess is that it got something to do with how cron spawns a new shell or something. Dont know. Any input would be great.

/Bashi

Replies are listed 'Best First'.
Re: Perl script in cron
by marto (Cardinal) on Dec 19, 2006 at 08:55 UTC
      Thanx for a quick answer. Im sorry Im not acustom with how this site works. Will make sure to be on my best behavior next time. You may already have answered my question though. I do rely on $ENV{'HOME'} when you menssioned it. Gonna check that out. Thanx again.

      /Roger
        bashi,

        don't worry about your behaviour, you have not upset anyone here. Welcome to the Monastery, I am sure you will get used to this place soon :).

        Cheers,

        Martin
Re: Perl script in cron
by f00li5h (Chaplain) on Dec 19, 2006 at 10:43 UTC

    One of the sysadmins at $job made me chant the following 10 times when i mentioned a bug like this

    Cron, at and batch run in a heavily cut down environment

    ... and would later ask me stuff like 'what is special about cron, at and batch?' or 'when might your script be running in a heavily cut down environment?'

    this went on for about a week, although i'm not sure what his point was...

    @_=qw; ask f00li5h to appear and remain for a moment of pretend better than a lifetime;;s;;@_[map hex,split'',B204316D8C2A4516DE];;y/05/os/&print;

      this went on for about a week, although i'm not sure what his point was

      nothing like public humiliation to prevent repeating bad behaviour.

      -derby
Re: Perl script in cron
by jonadab (Parson) on Dec 19, 2006 at 13:37 UTC

    Aren't RSA and DSA keys generally tied to a specific user account (and, in some cases, also a specific hostname)? If you're running out of cron, isn't it possible that you're running as a different user (e.g., root), and that your RSA and DSA keys are not valid for the other user account, only for yours?


    Sanity? Oh, yeah, I've got all kinds of sanity. In fact, I've developed whole new kinds of sanity. You can just call me "Mister Sanity". Why, I've got so much sanity it's driving me crazy.
      Well, the script is executed as the root user using roots rsa/dsa keys so I cant see that would be the problem. After turning on debugging for SSH in the script I found out that the passphrase authentication for the keys dont work under batchmode. And here is where I am at the moment, stuck :-) /Roger
        Net::SSH::Perl always reads passwords and passphrases from the terminal (the tty). Passphrases therefore don't work in batch mode, by design. See Is Net::SSH::Perl broken for login via explicit user/password? for more info.

        --shmem

        _($_=" "x(1<<5)."?\n".q·/)Oo.  G°\        /
                                      /\_¯/(q    /
        ----------------------------  \__(m.====·.(_("always off the crowd"))."·
        ");sub _{s./.($e="'Itrs `mnsgdq Gdbj O`qkdq")=~y/"-y/#-z/;$e.e && print}