GRID::Machine is a perl module for Remote Procedure Calls over a SSH link. With this module, we can create, change directories, run remote programs, run perl functions, copy and compile with make automatically among other things.
Note that in the other machine is possible that GRID::Machine module is not installed. Moreover, they may be different versions. This is very useful, especially in heterogeneous systems.
How to install?
GRID::Machine is available from CPAN. So, you can install it with cpan command or cpanm.
| $ cpanm GRID::Machine |
| $ perl -MGRID::Machine -e 1 |
Example
The following code is a very simple example to show this module. We have a list of machines and we want to run ps command for each machine. After we create the GRID Machine object, we can write a subrutine. This function will be ran in the other machine. In this example, we print the host and finally we print the result.
_________________________________________________________
1 #!/usr/bin/perl
2 use strict;
3 use GRID::Machine;
4
5 # List of machines
6 my @machines = qw/ localhost lab1 /;
7 my %m = {};
8
9 for (@machines) {
10 print "Creating object: $_\n";
11 my $gm = GRID::Machine->new(host=>$_, uses=>[qw(Sys::Hostname)]);
12 # We can installed a perl subrutine
13 $gm->sub(hostname=> q{
14 print " ----------- Machine: ".hostname()." ---------\n";
15 });
16 $m{$_} = $gm;
17 }
18
19 # ...
20
21 # Now, we run ps command for all machines
22 for (@machines) {
23 print "\n";
24 print $m{$_}->hostname();
25 print $m{$_}->system("ps --sort -pcpu aux | head -n 10");
26 }
27 ________________________________________________________
References

0 comentarios:
Publicar un comentario en la entrada