Script::Remote - Exceute Your Scripts Over SSH (And Pass Data Along)
# CASE 1: Simple case # Write a script first (say, foo.pl) use strict; print "Hello, World!\n"; # Elesewhere, in a different file use Script::Remote; my $remote = Script::Remote->new( script => 'foo.pl', hostname => 'some.host.com', ); $remote->run; #### CASE 2: With Data #### use strict; print "Hello, World from $config->{myname}\n"; $remote->run( variable => 'config', data => { myname => "Daisuke Maki" }, );
This is a stupid little hack that makes running scripts remotely a *bit* easier.
Please note that this is full of potential security gotchas. We generate code on the fly. This is bad. We're basically doing a remote eval(), which is just bad bad bad. DO NOT USE THIS MODULE if you expect people with no or minimal knowledge about how this kind of distributed system hacks work.
Having said that, for tests, this could be handy. All you need is a ssh-enabled set of machines (you probably want public key auth, too), and two scripts: the script you want to run remotely, and a script that will drive those script(s).
To run a single script on a single remote machine, simply say:
use Script::Remote; Script::Remote->new( script => 'foo.pl', hostname => 'my.host.name' )->run();
If you want to run the same script on multiple hosts, you need to tell Script::Remote to not block on wait(), so you need to use the no_wait parameter:
my $script = 'foo.pl'; my @scripts; my $data = ...; # some shared data foreach my $host (@hosts) { my $remote = Script::Remote->new( script => $script, hostname => $host, no_wait => 1, ); $remote->run(data => $data); push @scripts, $remote; } $_->wait_child for @scripts;
The name of the script to execute
The hostname to ssh to
The username to use for ssh
If true, the object will not block when run() is called. In that case you should use wait_child() to wait for the child process to stop
The full path to the remote perl executable. We use the *local machine's* value of $^X by default.
An alternate path to your ssh binary. We attempt to find one by default, but if we don't, you should be setting this or $Script::Remote::DEFAULT_SSH.
List of extra ssh command line arguments
Decide what to do with the output from the ssh child. Currently we simple dump everything to STDOUT (ideas, anybody?)
Copyright (c) 2008 Daisuke Maki <daisuke@endeworks.jp>
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
See http://www.perl.com/perl/misc/Artistic.html
1 POD Error
The following errors were encountered while parsing the POD:
=back doesn't take any parameters, but you said =back 4
To install Script::Remote, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Script::Remote
CPAN shell
perl -MCPAN -e shell install Script::Remote
For more information on module installation, please visit the detailed CPAN module installation guide.