我通过从本地服务器连接来在远程服务器上运行一些命令。为此,我使用@Entity
@Table(name = "IDENTITY")
public class Identity implements java.io.Serializable {
private Set<A> a;
}
@Entity
@Table(name = "A")
public class A implements java.io.Serializable {
private AId id;
private B b;
}
@Entity
@Table(name = "B")
public class B implements java.io.Serializable {
private BId id;
private String code;
private C c;
}
@Entity
@Table(name = "C")
public class C implements java.io.Serializable {
@Id
private String code;
private String name;
}
perl模块连接到远程服务器。连接在这里建立,但是有时当我执行命令时出现以下错误-
Net::SSH::Expect
这是我的代码:
Can't call method "send" on an undefined value at .....
首先,我正在构建命令并将其存储在my ($ip,$user,$passwd) = ("my.ip.address.here","user","password");
my $ssh = SSH_Connection( $ip,$passwd );
my $command_to_execute = "<Command to be executed will build here>";
print "$command_to_execute\n";
$str = 'Bye';
$ssh->send("$command_to_execute; echo $str");
$output = $ssh->waitfor($str,undef);
$ssh->close();
print "END\n";
sub SSH_Connection {
my ( $host,$passwd ) = @_;
my $ssh = Net::SSH::Expect->new (
host => $host,#ip
user => $user,#'user'
password => $passwd,#'password'
raw_pty => 1,no_terminal => 0,);
my $login_output;
my $handledie = eval {
$login_output = $ssh->login();
};
if ( $@ ) {
if ($@ =~ m/SSHConnectionError/i ) {
print "SSH Connection Error\n";
} elsif ( $@ =~ m/SSHProcessError/ix ) {
print "SSH Process Error\n";
} elsif ( $@ =~ m/SSHConnectionAborted/ix ) {
print "SSH Connection Aborted\n";
} else {
print "SSH Unknown Error: $@\n";
}
}
if ($login_output !~ /Last login/) {
die "Login has failed.";
} else {
return $ssh;
}
print "SSH to ip - $host failed\n";
}
变量中。
在命令执行结束时,我将获得关键字$command_to_execute
。因此,我正在等待该关键字匹配。
我的问题是-
- 为什么我遇到上述错误?
- 假设我的命令执行失败,控件将返回到我的脚本吗?因为它正在等待
Bye
字。
我怀疑错误捕获方法不正确。请提出更好的解决方案。