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 | [reply] [d/l] |
Re: Sending & Executing a perl script on remote machine.
by salva (Canon) on Oct 25, 2010 at 08:21 UTC
|
| [reply] |
|
|
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.
| [reply] |
|
|
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!"
| [reply] [d/l] |
Re: Sending & Executing a perl script on remote machine.
by zentara (Cardinal) on Oct 25, 2010 at 11:25 UTC
|
| [reply] |
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. | [reply] |
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) | [reply] |
|
|
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.
| [reply] |
|
|
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
| [reply] |
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.
| [reply] |