Perl Net::Telnet 模块
我正在尝试编写一个使用 Net::Telnet 代码的 perl 模块,但问题是提示符。我正在为其他用户编写应用程序,不确定他们可能有什么提示模式。有没有办法可以在运行时得到提示?
I am trying to write a perl module that uses the Net::Telnet code, but the problem is the prompt. I am writing the application for other user and not sure of what the prompt pattern they might have. Is there a way I can get the prompt at run time?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
![扫码二维码加入Web技术交流群](/public/img/jiaqun_03.jpg)
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
提示的默认值在几乎所有情况下都应该相当不错。
它查找以
#
或$
或%
后跟空格结尾的任何字符串。#
由 root 使用,%
由 C 风格 shell 使用,$
由 Bash 和 Kornshell 等 Bourne 风格 shell 使用。如果您使用 Telnet,则您登录的帐户很可能会使用默认提示。
我更喜欢使用 Net::SSH ::Perl 并且不用担心用户提示。
Net::SSH::Perl
更安全,我可以用它传输文件或执行命令。The default value for prompt should be pretty good in almost all circumstances.
It looks for any string that ends with either a
#
or a$
or a%
followed by a space. The#
is used by root, the%
is used by C Style shells, and the$
is used by Bourne style shells like BASH and Kornshell.If you're using Telnet, it's very likely you're logging into an account where the default prompt will work.
I prefer to use Net::SSH::Perl and not worry about user prompts.
Net::SSH::Perl
is more secure and I can transfer files, or execute commands with it.由于远程端的 Telnet 会产生一个新的 shell 会话,(你是对的)它取决于用户的配置文件,提示符的外观如何。 shell 通常从
PS1
变量读取提示格式。所以你需要执行类似的操作:来阅读提示的样子。
As Telnet on remote side spawns a new shell-session, (you are right) it depends on user's profile how the prompt will look like. It is common for shells to read the prompt format from
PS1
variable. So you need to execute something like:to read how the prompt looks like.