【发布时间】:2019-03-22 07:30:20
【问题描述】:
第一篇文章,一般来说是批处理和脚本的新手,所以请放轻松。
我的任务是编写一个 Perl 脚本,该脚本将启动与 6 部手机的 SSH 会话,并向它们发送一个 CLI 命令以重新启动它们。有趣的是,我知道 JACK 关于 Perl。我确实知道一点批处理自动化,并认为使用 plink 来做我需要的事情会很简单。我错了。
这是我的 plink 批处理示例。
@echo off
plink.exe -t -ssh XXXXXXX@111.111.1.1 -pw Abcd1234 < "C:\commands\commands.txt">output.txt
pause
Commands.txt:
debug
debug
reset hard
运行批处理文件会返回一个 cmd 窗口显示:Using Username "XXXXXXX" 我的 output.txt 显示:
debug
debug
reset hardsnoopyplus login:
此时我意识到在发送重置命令之前,我需要了解如何处理第二组登录凭据。
我们现在是第 3 天,我的老板想要一些结果。我的剧本有大约 4 次损坏的迭代和良好的态度。我可以尝试什么?
另外,这是我发现的一个 Perl 脚本的一部分,它声称能够处理我无法工作的 cisco 电话的 snoopyplus 调试登录。我发现的一点信息告诉我用 OpenSSH 重写它,我认为 Windows 不支持它。
sub reboot{
my ($ip,$sshpassword,$sshusername,$debuglogin,$debugusername,$debugpassword,$debugprompt,$command) = @_;
print "\nPlease be patient whilst Cisco phone at address $ip is rebooted. This may take up to 90 seconds to complete...\n";
my $ssh = Net::SSH::Perl->new("111.111.1.1");
my $login_output = $ssh->login();
#my $ssh->login($sshusername, $sshpassword) || myAuditLog(LOG,"Login has failed. $!");
$ssh->waitfor('/'.$debuglogin.'>.*$/');
$ssh->send($debugusername);
$ssh->waitfor('/Password :.*$/');
$ssh->send($debugpassword);
$ssh->waitfor('/'.$debugprompt.'>.*$/');
$ssh->exec($command);
$ssh->close();
【问题讨论】:
标签: perl batch-file ssh cisco