Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/batch-file/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Perl 批处理文件到SSH Cisco phone并重新启动它_Perl_Batch File_Ssh_Cisco - Fatal编程技术网

Perl 批处理文件到SSH Cisco phone并重新启动它

Perl 批处理文件到SSH Cisco phone并重新启动它,perl,batch-file,ssh,cisco,Perl,Batch File,Ssh,Cisco,第一篇文章,新的批处理和脚本一般,所以请对我轻松 我的任务是编写一个Perl脚本,用6部手机启动SSH会话,并向它们发送一个CLI命令以重新启动它们。有趣的是,我了解杰克关于Perl的知识。我知道一点批处理自动化,我想用plink做我需要的事情会很简单。我错了 下面是我的plink批次的一个示例 @echo off plink.exe -t -ssh XXXXXXX@111.111.1.1 -pw Abcd1234 < "C:\commands\commands.txt">outpu

第一篇文章,新的批处理和脚本一般,所以请对我轻松

我的任务是编写一个Perl脚本,用6部手机启动SSH会话,并向它们发送一个CLI命令以重新启动它们。有趣的是,我了解杰克关于Perl的知识。我知道一点批处理自动化,我想用plink做我需要的事情会很简单。我错了

下面是我的plink批次的一个示例

@echo off
plink.exe -t -ssh XXXXXXX@111.111.1.1 -pw Abcd1234 < "C:\commands\commands.txt">output.txt
pause
运行批处理文件将返回一个cmd窗口,显示:使用用户名“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();

如果您使用的是Windows,请看一看草莓Perl附带的。使用它,您应该能够与IP电话通话:

#!perl
use strict;
use warnings;
use Net::SSH2;

my $ssh2 = Net::SSH2->new();

$ssh2->connect('example.com') or $ssh2->die_with_error;

if ($ssh2->auth_password($debuglogin, $debugpassword)) {
    my $chan = $ssh2->channel();
    $chan->shell();
    while (!$channel->eof) {
        if (my ($o, $e) = $channel->read2) {
            $out .= $o;
            $err .= $e;
        } else {
            $ssh2->die_with_error;
        }
    }
};

请尝试以下plink命令格式:

plink.exe -t -ssh -pw Abcd1234 -m "C:\commands\commands.txt" XXXXXXX@111.111.1.1 >output.txt

谢谢你的回复。运行该格式后,在cmd窗口关闭之前,我会看到一个闪烁的cmd窗口,output.txt为空。在以前的迭代中,我无法使“-m”正常工作,它只在我尝试删除输出重定向
>output.txt
并使用命令
pause
再添加一行时运行,例如:
@echo off plink.exe-t-ssh-pw Abcd1234-m“C:\commands\commands.txt”XXXXXXX@111.111.1.1暂停
(请原谅我从未尝试在注释中嵌入代码的编辑。)上面的代码显示了一个已激活暂停的cmd窗口。没有迹象表明它实际运行了命令。因此,请先打开控制台窗口,然后键入命令并按enter键?现在发生了什么?谢谢!我在研究与Windows兼容的Net::SSH:Expect的替代方案时查看了Net::SSH2,但不幸的是,我几乎不知道语言的边缘我恐怕看不懂你的代码了。我已经安装了草莓Perl,我正在学习一些初级课程来掌握我的方向。与此同时,我还在修补批处理文件和Putty,祈祷我能有所突破!
plink.exe -t -ssh -pw Abcd1234 -m "C:\commands\commands.txt" XXXXXXX@111.111.1.1 >output.txt