2
我運行下面的腳本:獲得退出狀態::期待
#!/usr/local/bin/perl -w
use strict;
use warnings;
use Net::SSH::Expect;
my $ssh = Net::SSH::Expect->new(host=>"xxx.xxx.xxx.xxx",password=>"xxxxxxx", user=>"root" ,timeout=>3 );
$ssh->login();
$ssh->exec("stty -echo");
print "Connection Established\n";
my ($out) = $ssh->exec("rpm -ivh xxx");
print "\n\nOUTPUT: $out\n";
#$ssh->send("echo $?");
($out) = ($ssh->get_expect())->exitstatus();
print "\n\nEXIT STATUS: $out\n";
運行這個,我沒能拿到「轉的退出狀態-ivh ...「命令,我執行。
我是Perl新手,請幫我解決這個問題。
爲什麼括號左右($出來)?文檔沒有這些。 (https://metacpan.org/release/Net-SSH-Expect) 另外,如果您有「使用警告」,則可以在第一行中刪除-w標誌。 – davewood
@davewood。當然,你應該嘗試'$ out = $ ssh-> exec(「rpm -ivh xxx」);'...但是這並不能解決你對'$?'的渴望,也不能解決遠程提示和/或prompt_command。 – Ouki