Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Running a Net::SFTP::Foreign script from cron

by rah (Monk)
on Nov 07, 2006 at 21:01 UTC ( [id://582733]=perlquestion: print w/replies, xml ) Need Help??

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

I wrote a script using the Net::SFTP::Foreign module for performing unattended sftp file transfers. The script works beautifully from the command line on any platform. It also performs without problems when called from cron on MacOS X or on Redhat Linux. However when I try to run the same script from cron on HP-UX or AIX, it fails with a broken pipe error. The failure is

open2: exec of ssh -l user some.location.com -s sftp failed at /usr/local/lib/perl5/site_perl/5.8.0/Net/SFTP/Foreign.pm line 67

Additionally, HP-UX complains about write to ssh pipe error, while AIX complains about a read from ssh pipe error. The setup uses an RSA key, so the script does not prompt for any user input. Does anyone know what is going on and/or how I might be able to coax this script to run from cron?

Replies are listed 'Best First'.
Re: Running a Net::SFTP::Foreign script from cron
by grep (Monsignor) on Nov 07, 2006 at 21:15 UTC
    Your cron does not have access to your shell PATH and Net::SFTP::Foreign uses the ssh command line utility (as opposed to Net::SFTP which is pure-perl). ssh is not in cron's path (but it is in yours), so Net::SFTP::Foreign can't find it

    The remedy is either to switch to Net::SFTP or to set ssh_cmd => $sshcmd to the full path of your ssh.

    my $sftp = Net::SFTP::Foreign->new('host',{ ssh_cmd => '/usr/bin/ssh' +});


    grep
    One dead unjugged rabbit fish later
      Thank you so much. I must have had one of those duh moments. ssh is in /usr/bin on my two systems that work (and therefore in my sparse cron environment), but installed elsewhere on my two systems that failed. Good catch. Works fine now.
      For Windows users, the process is slightly more convoluted.
      Seems like setting ssh_cmd => $sshcmd still results in a "Unable to connect: Connection to remote server is broken" error.

      My solution to this was to create a ".bat" batch file which contains the command to execute the script perl "D:\Projects\sftp.plx"
      Then using "Scheduled Task" to run the above batch file under a user account which can see the path specified in $ssh_cmd
Re: Running a Net::SFTP::Foreign script from cron
by salva (Canon) on Nov 08, 2006 at 16:36 UTC
    question added to the module docs as a FAQ ;-)

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others cooling their heels in the Monastery: (4)
As of 2024-12-12 17:10 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Which IDE have you been most impressed by?













    Results (65 votes). Check out past polls.