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");
# ...
精彩评论