1

我有一个 perl 脚本,它调用一个命令,在执行之前要求确认。我如何在 Perl 中处理这个问题?

例如,在我的 perl 脚本中说我正在执行以下操作

`ssh myServer`;

在连接之前,我会收到一个提示,询问是否继续。我必须提供 yes 作为我的下一个命令。我怎样才能做到这一点?任何代码片段都会很有用。

4

2 回答 2

1

If you are looking at interactive you can use Expect on the CPAN...

"Expect is a generic tool for talking to processes that normally require
user interaction. This might be running an ftp client to grab a file,
telnetting to a router to grab statistics or reset an interface. Or, as in the
case of a place I recently administered, to start up a secure webserver without
having to be physically at the machine to enter the super secret password."

However, there are other (better) methods to automate SSH login. I.e. by using ssh-keygen

于 2013-06-07T11:31:09.643 回答
0

From Net::SSH :

interactive Set to a true value if you're using Net::SSH::Perl interactively. This is used in determining whether or not to display password prompts, for example. It's basically the inverse of the BatchMode parameter in ssh configuration.

Defaults to false.

于 2013-06-07T11:30:53.440 回答