1

So, I've established a connection via ssh to a remote machine; and now what I would like to do is to execute few commands, grab some files and copy them back to my host machine.

I am aware that I can run

ssh user@host "command1; command2;....command_n"

and then close the connection, but how can I do the same without use the aforememtioned syntax? I have a lot of complex commands that has a bunch of quote and characters that would be a mess to escape.

Thanks!

4

3 に答える 3

0

シェルの代わりに、いくつかのスクリプト言語 (Perl、Python、Ruby など) と、醜い作業を処理するモジュールを使用します。例えば:

#!/usr/bin/perl
use Net::OpenSSH;
my $ssh = Net::OpenSSH->new($host, user => $user);
$ssh->system('echo', 'Net::Open$$H', 'Quot%$', 'Th|s', '>For', 'You!');
$ssh->system({stdout_file => '/tmp/ls.out'}, 'ls');
$ssh->scp_put($local_path, $remote_path);
my $out = $ssh->capture("find /etc");
于 2013-10-23T06:21:56.183 に答える