in reply to running script remotely
This is untested, probably unsafe and assumes unix. The basic idea is simple, if we aren't on the remote host copy ourself there otherwise do what we were written for.
I've also assumed that you can install all the required modules;-)use strict; use warnings; use Sys::Hostname; chmod 0700, $0; my $remote_host = 'somewhere'; my $user_name = 'somebody'; my $password = 'something'; if ( hostname ne $remote_host ) { require Net::SFTP; require File::Basename; require Net::SSH::Perl; my $remote_file = basename $0; my $sftp = Net::SFTP->new( $remote_host, user => $user_name, password => $password ); $sftp->put( $0, $remote_file ); my $ssh = Net::SSH::Perl->new($remote_host); $ssh->login( $user_name, $password ); $ssh->cmd($remote_file); } else { unlink $0; # do your stuff here }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: running script remotely
by mercuryshipz (Acolyte) on Feb 04, 2008 at 15:57 UTC | |
by hipowls (Curate) on Feb 05, 2008 at 20:45 UTC |