Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Re: Using Perl to do SCP

by Rhys (Pilgrim)
on Sep 15, 2004 at 16:03 UTC ( #391225=note: print w/ replies, xml ) Need Help??


in reply to Using Perl to do SCP

Okay, I did both of what I suggested to myself. :-) I wrote a new error_handler sub with use Data::Dumper, plus I wrote some extra code in there to clean up the data passed through @_. Here's what I used:

sub showme { use Data::Dumper; print Dumper(@_); print "\n"; foreach ( @_ ) { chomp $_; print "Thing is $_.\n"; } exit; }

As it turns out, the problem is the way the switch closes the connection at the end of the file transfer. Apparently, Net::SCP::Expect doesn't expect (pardon the pun) the string it gets. So here's the code I'm using (successfully, so far) in the production script to handle it:

sub scp_errors { use strict; my $line = shift; if ( $line =~ /Connection.+closed by remote host/ ) { # This is expected from an 8600. return(0); } else { # Get rid of CR and LF. $line =~ s/\012//g; $line =~ s/\015//g; print "Got error pulling file:\n"; print "\t", $line; print "\n"; return(1); } }

As far as I can tell, only one error line gets passed to the error handler. If this turns out not to be the case later, I'll have to change scp_errors to deal with multiple args.

--J


Comment on Re: Using Perl to do SCP
Select or Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (7)
As of 2014-10-21 02:36 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    For retirement, I am banking on:










    Results (95 votes), past polls