gpt4 book ai didi

用于远程登录 eagle stp 设备的 perl 脚本

转载 作者:行者123 更新时间:2023-12-02 01:58:47 25 4
gpt4 key购买 nike

我需要一个脚本来远程登录到 eagle STP 设备并在那里运行命令。

当我尝试从命令提示符远程登录 eagle STP 设备时,

我得到以下输出:

[root@localhost tmp]# telnet hostname port
Trying hostname...
Connected to hostname hostname).
Escape character is '^]'.

我在这里没有得到任何匹配 perl 脚本的提示。我们需要按 control+a 才能得到提示。如果我们按 control+a,它将给出以下输出

[root@localhost tmp]# telnet hostname port
Trying...
Connected to hostname.
Escape character is '^]'.


>

然后我们需要在这个提示符下输入login:uid

> login:uid=dumps

然后提示输入密码

Enter password : password

然后我们需要再次按下 control+a 来执行命令。

> rtrv-dstn.

我在这里被击中了,我无法在 telnet 命令后通过 control+a 命令。

我用下面的方式写了脚本。但它不起作用。任何人都可以帮助我吗!!!!

#!/usr/bin/perl
use Net::Telnet;
my $host='hostname';
my $port='port';
my $telnet = new Net::Telnet(Host => $host, Port => $port, Timeout => 20)
or die "connect failed: $!";
$telnet->open($host);
print"Hi iii";
$telnet->waitfor('+$/i');');
print"Hello";
$telnet->print("^]");
$telnet->waitfor('/>$/i');
$telnet->print("login:uid=username");
$telnet->waitfor('/Enter Password :\s+$/i');
$telnet->print("password");
$telnet->waitfor('/>$/i');
@res1=$telnet->print("rtrv-dstn");
print"@res1";
Exit;

最佳答案

来自 Net::Telnet :

print - write to object

This method writes @list followed by the output record separator to the open object and returns 1 if all data was successfully written. On time-out or other failures, the error mode action is performed. See errmode().

您可以通过 $telnet->ors("\x01"); 或使用以下方法设置 output_record_separtor:

$telnet->cmd("\x01");

在需要时发送 Ctrl-A。没有用于测试的 Eagle STP,但我希望这会有所帮助。

顺便说一句,您应该始终检查每个方法调用的输出以确保其正常工作。

关于用于远程登录 eagle stp 设备的 perl 脚本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18361180/

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