Net-PDSH

 view release on metacpan or  search on metacpan

PDSH.pm  view on Meta::CPAN

#
# PDSH.pm
#
# Interface for Parallel Distributed shell
#
package Net::PDSH;

use strict;
use vars qw($VERSION @ISA @EXPORT_OK $pdsh $equalspace $DEBUG @pdsh_options 
            $list_options $set_credentials $set_batch_mode $set_connect_timeout 
            $set_command_timeout $set_fanout $set_remote_command $list_modules);

use Exporter;
use POSIX ":sys_wait_h";
use IO::File;
use IO::Select;
use IPC::Open2;
use IPC::Open3;
use Data::Dumper;
use String::Util ':all';

@ISA = qw(Exporter);
@EXPORT_OK = qw(pdsh pdsh_cmd pdshopen2 pdshopen3 list_options pdsh_options
                DEBUG set_batch_mode set_credentials set_connect_timeout
                set_command_timeout set_fanout set_remote_commmand
                list_moodules);
$VERSION = '0.01';

$DEBUG = 1;

$pdsh = "pdsh";
$list_options = "list_options";
$list_modules= "list_modules";
$set_remote_command = "set_remote_command";
$set_credentials = "set_credentials"; 
$set_batch_mode = "set_batch_mode";
$set_connect_timeout = "set_connect_timeout";
$set_command_timeout = "set_command_timeout";
$set_fanout = "set_fanout";
$set_remote_command = "set_remote_command";
$list_modules = "list_modules";

sub new {
  my($class,%args) = @_;
  my $self = {};
  bless($self,$class);
  $self->{_DEBUG} = 0;
  $self->{_pdsh_options} = 0;
  $self->{_batch_mode} = 0;
  $self->{_user} = "";
  $self->{_connect_timeout} = 0;
  $self->{_command_timeout} = 0;
  $self->{_fanout} = 0;
  $self->{_rcmd} = "";
  return $self;
}


=head1 NAME

Net::PDSH - Perl extension for parallel distributed shell

PDSH.pm  view on Meta::CPAN

    push @pdsh_options, ("-R", $self->{_rcmd});
  } else {
    push @pdsh_options, ("-R", "exec") if $DEBUG == 1;
  }
  if ($self->{_user} ne "") {
    push @pdsh_options, ("-l", $self->{_user});
  }
  if ($self->{_connect_timeout} != 0) {
    push @pdsh_options, ("-t", $self->{_connect_timeout});
  }
  if ($self->{_command_timeout} != 0 ) {
    push @pdsh_options, ("-u", $self->{_command_timeout});
  }
  my @cmd = ($pdsh, @pdsh_options, "-w $host", @command);
  warn "[Net::PDSH::pdsh] executing ". join(' ', @cmd). "\n"
    if $DEBUG;
  @cmd = join(' ', @cmd);
  system(@cmd);
}

=item cmd 

PDSH.pm  view on Meta::CPAN

      push @pdsh_options, ("-R", $self->{_rcmd});
    } else {
      push @pdsh_options, ("-R", "exec") if $DEBUG == 1;
    }
    if ($self->{_user} ne "") {
      push @pdsh_options, ("-l", $self->{_user});
    }
    if ($self->{_connect_timeout} != 0) {
      push @pdsh_options, ("-t", $self->{_connect_timeout});
    }
    if ($self->{_command_timeout} != 0) {
      push @pdsh_options, ("-u", $self->{_command_timeout});
    }
    if ($DEBUG == 1) {
      push @pdsh_options, ("-d") ;
    }
    my @cmd2 = $cmd{command};
    my @arguments = $cmd{arguments};
    my $pid = pdshopen3($cmd{hostname}, $writer, $reader, $error, @cmd2);
    waitpid($pid, WNOHANG);
    my $buffer;
    while(<$reader>) {

PDSH.pm  view on Meta::CPAN

  my ($self, $user) = @_;
  $self->{_user} = $user;
  return $self->{_user};
}

sub set_connect_timeout {
  my ($self, $val) = @_;
  $self->{_connect_timeout} = $val;
  return $self->{_connect_timeout};
}
sub set_command_timeout {
  my ($self, $val) = @_;
  $self->{_command_timeout} = $val;
  return $self->{_command_timeout};
}
sub set_fanout {
  my ($self, $val) = @_;
  $self->{_fanout} = $val;
  return $self->{_fanout};
}
sub set_remote_command {
  my ($self, $val) = @_;
  $self->{_rcmd} = $val;
  return $self->{_rcmd};

test.pl  view on Meta::CPAN

  { "hostname" => "127.0.0.1,127.0.0.1",
    "command" =>  ["/bin/cat", "/tmp/lfsck.log", "/etc/hosts", ],
  },
  { "hostname" => "127.0.0.1",
    "command" =>  ["/bin/cat", "/etc/sysconfig/network",],
  },
);
# $pdsh->set_remote_command("ssh");
$pdsh->set_credentials("build");
# $pdsh->set_connect_timeout(5);
$pdsh->set_command_timeout(5);
# optional pdsh_options that can be given manually.
my %pids = $pdsh->cmd(@cmd_arr);
foreach ($val, keys %pids) {
  print "Output:".$pids{$_}."\n";
}
my %options = $pdsh->list_options("localhost");
print Dumper(\%options);
my %options = $pdsh->list_modules("localhost");
print Dumper(\%options);



( run in 0.240 second using v1.01-cache-2.11-cpan-4d50c553e7e )