Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Net::OpenSSH::Parallel documentation

by ashok.g (Beadle)
on Apr 09, 2012 at 10:59 UTC ( [id://964106]=perlquestion: print w/replies, xml ) Need Help??

ashok.g has asked for the wisdom of the Perl Monks concerning the following question:

Hi,

Is there any good documentation that describes the full use of Net::OpenSSH::Parallel Perl module?

I did check this on Net::OpenSSH::Parallel but unable to get full fledged examples in that link.

Actually my script will look like this:
#!/usr/bin/perl use strict; use warnings; use Net::OpenSSH::Parallel; my @hosts=('192.168.0.19','192.168.0.18'); my $pssh = Net::OpenSSH::Parallel->new(); sub task() { print "Hi\n"; } foreach my $host ( @hosts ) { $pssh->add_host($host,user =>'root',passwd=>'access',on_error=>($p +ssh, $host, 'OSSH_ON_ERROR_IGNORE',task())); } my $path='/tmp/a.txt'; my $destination='/tmp/a.txt'; $pssh->push('*', scp_put => $path, $destination) or print "UNABLE to P +USH"; $pssh->run or print "RUN FAILED";

An when I execute
[root@station182 Perl]# perl SSH_Parallel.pl Hi Hi

Here I am looking for the debugging techniques like: how to get the errors in each steps like add_host, push and run. Also, how can I continue based on the error code we get like for run.

Please advice.

Thanks,
Ashok.

Replies are listed 'Best First'.
Re: Net::OpenSSH::Parallel documentation
by repellent (Priest) on Apr 10, 2012 at 07:07 UTC
    The Error Handling section gives some pretty good pointers. For instance, you may want to specify on_error in one of the following ways:

    useNet::OpenSSH::Parallel::Constants qw(:error :on_error);
    # with a coderef $pssh->add_host($host, user =>'root', passwd=>'access', on_error=> sub { my ($pssh, $label, $error, $task) = @_; $error == OSSH_JOIN_FAILED and do { ... }; $error == OSSH_ABORTED and do { ... }; $error == OSSH_GOTO_FAILED and do { ... }; }, ); # or with constants $pssh->add_host($label, on_error => OSSH_ON_ERROR_IGNORE); $pssh->add_host($label, on_error => OSSH_ON_ERROR_ABORT_ALL);
      Thanks for update.

      So, we need to compare each time the $error with some Error constant always?

      Thanks,
      Ashok
        $error should be compared with the Error constants because the documentation mentions that it would be one of the constant values.

        The coderef is just an example. You're free to do whatever you want with it.
      Hi,

      The following code gives no result:
      #!/usr/bin/perl use strict; use warnings; use Net::OpenSSH::Parallel; use Net::OpenSSH::Parallel::Constants qw(:error :on_error); my @hosts=('192.168.0.19','192.168.0.18'); my $pssh = Net::OpenSSH::Parallel->new(); my @errors=(OSSH_ON_ERROR_IGNORE,OSSH_ON_ERROR_RETRY,OSSH_ON_ERROR_DON +E,OSSH_ON_ERROR_ABORT,OSSH_ON_ERROR_ABORT_ALL,OSSH_JOIN_FAILED,OSSH_A +BORTED,OSSH_GOTO_FAILED); foreach my $host ( @hosts ) { $pssh->add_host($host,user =>'root',passwd=>'access', on_error +=> sub { my ($pssh, $label, $error, $task) = @_; foreach my $err ( @errors ){ if ( $error =~ m/$err/ ){ print "---$task----\n"; } } } ); }
      But
      #!/usr/bin/perl use strict; use warnings; use Net::OpenSSH::Parallel; use Net::OpenSSH::Parallel::Constants qw(:error :on_error); my @hosts=('192.168.0.19','192.168.0.18'); my $pssh = Net::OpenSSH::Parallel->new(); my @errors=(OSSH_ON_ERROR_IGNORE,OSSH_ON_ERROR_RETRY,OSSH_ON_ERROR_DON +E,OSSH_ON_ERROR_ABORT,OSSH_ON_ERROR_ABORT_ALL,OSSH_JOIN_FAILED,OSSH_A +BORTED,OSSH_GOTO_FAILED); foreach my $host ( @hosts ) { $pssh->add_host($host,user =>'root',passwd=>'access') or print + "Error----\n"; }
      Gives me:
      [root@station20 cgi-bin]# perl NetOpenSSHParallel.pl Error---- Error----

      Still missing anything here??

      Thanks,
      Ashok.
Re: Net::OpenSSH::Parallel documentation
by osbosb (Monk) on Apr 10, 2012 at 14:33 UTC
    use print statements to debug your code until you're sick in the head.

    print is friend.

      I am able to check the failing statements but I can't see what the specif error was.

      Check the error for some debuggiing.

      Thanks,
      Ashok
        ... $pssh->run; my %errors = $pssh->get_errors; while (my ($label, $error) = each %errors) { print "label $label, error: $error\n"; }

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others browsing the Monastery: (10)
As of 2024-04-18 15:56 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found