开发者

expect usage after ssh connection

I am able to use expect to connect automatically with SSH. However, I have a lot of shell commands and shell conditions to be executed or tested after the connection. I am wondering how I can deal with this situation. It looks like putting the shell commands in the expect scrip开发者_Python百科t and use send is not a good option. Are there any other options?


In Perl you can use Net::SSH2, Net::OpenSSH or even the old Net::SSH::Perl

use Net::OpenSSH;
my $ssh = Net::OpenSSH->new('host.example.com', user => 'jsmith', password => 'jsmith2011');
$ssh->error and die "Unable to connect to remote host: " . $ssh->error;

$ssh->system("ls /etc");
my $output = $ssh->capture("rgrep hello /usr/share/doc");
$ssh->scp_get("/var/log/messages", "/tmp/remote_log");
# ...
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜