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.

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 }
I've also assumed that you can install all the required modules;-)

Replies are listed 'Best First'.
Re^2: running script remotely
by mercuryshipz (Acolyte) on Feb 04, 2008 at 15:57 UTC
    thanks hipowls...

    if the script is copied to the remote machine, can we delete the script on the remote as soon as the result is returned.

      The first thing the example does is to delete itself. Once the perl interpreter has read it, it is no longer required.