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

Hi All, I have 20 node cluster of machines on which i am running RHEL5.4. I need to set some settings and variables on all the nodes. For this purpose i have one machine which acts like a server & send Perl script to all other machine and than execute that script. My problem is I am able to send the script using File::Remote copy function, but still the execution and taking back the result is problem. I have tried executing the script using IPC::PerlSSH module but that is also failing. Please help me if there is any better way or module so that I can send my script to all the nodes and execute. Thanks in advance.. UPDATE A lot of thanks to all of you for giving me so many useful options. But I have few constraints: -> There should not be any installation( Even any perl Module) or settings that I have to do on my remote machines. -> Now i have 20 machines but they can be 1000 also, so I need a solution which doesn't have problem with heavy loads. -> On my Server machine I can do all the stuffs, so I need a solution which doesn't require any extra efforts on my remote nodes.
  • Comment on Sending & Executing a perl script on remote machine.

Replies are listed 'Best First'.
Re: Sending & Executing a perl script on remote machine.
by sflitman (Hermit) on Oct 25, 2010 at 07:01 UTC
    Assuming you have keychain running and have copied your server's id_rsa.pub to every client's authorized_keys file, and your script is already uploaded (executable bit set, and all its dependencies!), then you can just iterate in your favorite scripting language and execute this:
    `ssh name@host$num '/path/to/myscript'`
    And you will get the script's stdout output back. Now if it has to be a different script over and over, I suspect that can be automated by simply using File::Remote to send the script over first to each host (but remember the executable bit and its required modules).

    HTH,
    SSF

Re: Sending & Executing a perl script on remote machine.
by salva (Canon) on Oct 25, 2010 at 08:21 UTC

      The Net::OpenSSH::Parallel module I am able to complete my task. But still I want to have a library of modules that I can share with my remote nodes. So that I needn't to send a script file every time. I found out that IPC::PerlSSH::Library module is what i required But still I am not sure what are the changes library requires, so that they can be load using load_library function.

        I have just released a new version of Net::OpenSSH::Parallel supporting the rsync functionality available from Net::OpenSSH.

        That would allow to maintain a library of perl modules and scripts replicated across all your servers, though it needs the rsync binary installed on them!

        use Net::OpenSSH::Parallel; my $p = Net::OpenSSH::Parallel->new; $p->add_host($_) for @hosts; $p->push('*', 'rsync_put', { recurse => 1 }, '/my/local/perl/library', '/tmp/my-perl'); $p->push('*', 'command', { stdout_file => '%HOST.out', stderr_file => '%HOST.err' }, '/usr/bin/perl -I/tmp/my-perl/lib /tmp/my-perl/script.pl +'); $p->run or die "something failed!"
Re: Sending & Executing a perl script on remote machine.
by zentara (Cardinal) on Oct 25, 2010 at 11:25 UTC
Re: Sending & Executing a perl script on remote machine.
by sierpinski (Chaplain) on Oct 25, 2010 at 13:07 UTC
    Personally I'm a huge fan of Net::SSH::Expect and Parallel::ForkManager. Instead of sending a Perl script to the host and executing it, you could have a script that connects to each host and executes commands remotely (where the SSH object comes into play) and then return the results. Parallel ForkManager lets you do that on multiple hosts at once.

    One caveat, obviously environments differ, but I found out that in my environment, setting max_procs (the maximum number of processes) to more than 20 saturated our LDAP server and started getting 'cannot connect' messages. Just some food for thought if you go that way.
Re: Sending & Executing a perl script on remote machine.
by locked_user sundialsvc4 (Abbot) on Oct 25, 2010 at 13:12 UTC

    When you start going down this road, be sure you know where it really ends, and observe if it is “choked with weeds and abandoned,” or “well-paved and obviously recently-trod.”   If what you really need is a lightweight batch-process monitor, then there are plenty to choose from in CPAN.   There needs to be a little alarm that goes off that says, “aren’t I doing something that has been done, hundreds if not thousands of times before?”   The answer in this case is undoubtedly, “yes.”   Therefore, troll CPAN first.   You will find something that is a more thorough and well thought out solution than you could ever cobble together by hand, and it is just about true to say that you can “just drop it in.”

Re: Sending & Executing a perl script on remote machine.
by Plankton (Vicar) on Oct 25, 2010 at 15:58 UTC
    Setup a YUM server on your one machine that acts like a server. (see http://yum.baseurl.org/ or do an internet search for yum server)
      i too would go the simple route. if you already have your script but aren't getting output, just setup syslog from your remote machines to go to your one box and print to your log.
        Setting up a YUM server is pretty simple but RPM spec files can be complex or simple depending. I think the YUM server / RPM approach is keeping with the "do not re-invent the wheel" school of thinking. http://www.rpm.org/max-rpm/ch-rpm-inside.html
Re: Sending & Executing a perl script on remote machine.
by rohit_ch (Initiate) on Oct 26, 2010 at 07:16 UTC

    A lot of thanks to all of you for giving me so many useful options. But I have few constraints:

    -> There should not be any installation( Even any perl Module) or settings that I have to do on my remote machines.

    -> Now i have 20 machines but they can be 1000 also, so I need a solution which doesn't have problem with heavy loads.

    -> On my Server machine I can do all the stuffs, so I need a solution which doesn't require any extra efforts on my remote nodes.