使用Perl的期望
我的情况是,在我调用以下perl脚本的情况下,
if (param("lremail") && param("lot")) {
my $address=param("lremailaddress");
my $lot=param("lot");
print a({-href=>"$dir/new.pl"},"Back to Top"),br;
print "Request submitted for $address.",br;
print "Lot $lot",br;
print "You will receive an e-mail with a link to the data when the request is complete.";
print end_html;
system ("ssh SERVERNAME /test/abc.csh $lot $$ $address &");
exit(1);
上面的脚本不运行,因为当我执行系统时,请提示系统以获取密码。然后我查找它并找到了下面的命令。
> expect -c 'spawn ssh SERVERNAME /test/abc.csh J213520 06 [email protected] "ls -lh file"; expect "Password:"; send "PASSWORD\r"; interact'
上面的命令成功执行,没有任何问题,但仅从命令行中执行。当我将相同的(通过替换System
调用)中时,它会失败。 如何将其合并到第一个脚本中?
I have a situation where in I am calling the below Perl script
if (param("lremail") && param("lot")) {
my $address=param("lremailaddress");
my $lot=param("lot");
print a({-href=>"$dir/new.pl"},"Back to Top"),br;
print "Request submitted for $address.",br;
print "Lot $lot",br;
print "You will receive an e-mail with a link to the data when the request is complete.";
print end_html;
system ("ssh SERVERNAME /test/abc.csh $lot $ $address &");
exit(1);
The above script does not run because when I execute the system is prompted for a password. Then I looked it up and found the below command..
> expect -c 'spawn ssh SERVERNAME /test/abc.csh J213520 06 [email protected] "ls -lh file"; expect "Password:"; send "PASSWORD\r"; interact'
The above command is executed successfully without any issue but from the command line only. When I incorporate the same(by replacing the system
call) within the Perl script, it fails.
How can I incorporate within the first script?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
有一个期望 perl的模块。
但是,我倾向于编写直截了当的期望脚本,并从Perl打电话给它们。这样,我可以自己使用期望脚本。但是,我曾经做过很多TCL。
There's an Expect module for Perl.
However, I tend to write straight expect scripts and call them from Perl. That way I can use the expect scripts on their own. But then, I used to do a lot of Tcl too.