gpt4 book ai didi

linux - 如何在脚本中使用两个 CPAN 模块

转载 作者:太空宇宙 更新时间:2023-11-04 09:39:40 24 4
gpt4 key购买 nike

在这里,我尝试在脚本中使用两个 CPAN 模块。除了我在代码中使用的方法之外,还有其他正确的使用方法吗?

#!/usr/bin/perl -w
$host='example/cp,';
$user='usertest';
$pass='kjasdkjd';
$cmd='su -';
$stdin='jkhasdj';
#$cmd='passwd';
use Net::SSH::Perl;
my $ssh = Net::SSH::Perl->new("$host", options => [
"use_pty 1", "interactive true"]);
$ssh->login($user, $pass);
#my($stdout, $stderr, $exit) = $ssh->cmd($cmd,[$stdin]);
#$ssh->shell;
#print ("$stdout\n");
#print ("$stderr\n");
#print ("$exit\n");

use Net::SSH::Expect;
$ssh->send("passwd");
$ssh->waitfor('password:\s*\z', 1) or die "prompt 'password' not found after 1 second";
$ssh->send("frghthhyj");
$ssh->waitfor(':\s*\z', 1) or die "prompt 'New password:' not found";
$ssh->send("redhat");
$ssh->waitfor(':\s*\z', 1) or die "prompt 'Confirm new password:' not found";
$ssh->send("redhat");

我收到错误“无法通过包“Net::SSH::Perl::SSH2”找到对象方法“send”,尽管“send”方法与“Net::SSH::Expect”脚本在“Net::SSH::Perl”中寻找方法,这是不正确的。

最佳答案

查看 Net::SSH::Expect 的文档.它显示了如何创建对象实例、登录等。

您无法通过 Net::SSH::Perl 登录并神奇地将您的实例 $ssh 转换为 Expect 对象。从一开始就使用 Expect。

关于linux - 如何在脚本中使用两个 CPAN 模块,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22755281/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com