NAME
Net::PDSH - Perl extension for parallel distributed shell
SYNOPSIS
use Net::PDSH;
my $pdsh = Net::PDSH->new;
$pdsh->pdsh("remotehost", "/bin/ls");
cmd( [
{
user => 'user',
host => 'host.name,host.name,...',
command => 'command',
args => [ '-arg1', '-arg2' ],
stdin_string => "string\n",
},
{
user => 'user',
host => 'host.name,host.name,...',
command => 'command',
args => [ '-arg1', '-arg2' ],
stdin_string => "string\n",
}
]
);
DESCRIPTION
Simple wrappers around pdsh commands.
- cmd
-
Calls pdsh in batch mode. Throws a fatal error if data occurs on the command's STDERR. Returns any data from the command's STDOUT.
If using the hashref-style of passing arguments, possible keys are:
host (requried) command (required) args (optional, arrayref) stdin_string (optional) - written to the command's STDIN
- set_batch_mode
-
Executes pdsh in batchmode
Input: 0/1
- set_credentials
-
Executes pdsh under a given user. All the further commands would be executed as that user.
Input: username
EXAMPLE
my @cmd_arr = (
{ "hostname" => "remotehost1,remotehost2",
"command" => ["/bin/cat", "/tmp/fsck.log", "/etc/hosts", ],
},
{ "hostname" => "remotehost3",
"command" => ["/bin/cat", "/etc/sysconfig/network",],
},
);
my %pids = $pdsh->cmd(@cmd_arr);
This would execute "cat /tmp/fsck.log /etc/hosts" on remotehost1 and remotehost2
and it would execute "cat /etc/sysconfig/network" on remotehost3
It would return the output in %pids hash table where keys are pids and values are
output contents
FREQUENTLY ASKED QUESTIONS
Q: How do you supply a password to connect with pdsh within a perl script using the Net::PDSH module?
A: You don't (at least not with this module). Use RSA or DSA keys. See the quick help in the next section and the ssh-keygen(1) manpage.
A #2: See Net::SSH::Expect instead.
GENERATING AND USING SSH KEYS
- 1 Generate keys
-
Type:
ssh-keygen -t rsa
And do not enter a passphrase unless you wanted to be prompted for one during file copying.
Here is what you will see:
$ ssh-keygen -t rsa Generating public/private rsa key pair. Enter file in which to save the key (/home/User/.pdsh/id_rsa): Enter passphrase (empty for no passphrase): Enter same passphrase again: Your identification will be saved in /home/User/.ssh/id_rsa Your public key will be saved in /home/User/.ssh/id_rsa.pub
- 2 Copy public to machines you want to upload to
-
id_rsa.pub
is your public key. Copy it to~/.ssh
on target machine.Put a copy of the public key file on each machine you want to log into. Name the copy
authorized_keys
(some implementations name this fileauthorized_keys2
)Then type:
chmod 600 authorized_keys
Then make sure your home dir on the remote machine is not group or world writeable.
AUTHORS
Aditya Pandit <adityaspandit@gmail.com>
COPYRIGHT
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
SEE ALSO
Net::SSH::Perl, Net::SSH::Expect, Net::SSH2, IPC::PerlSSH, pdsh(1)