为 Telnet 会话创建脚本? [英] Creating a script for a Telnet session?
问题描述
有谁知道一种简单的方法来创建一个可以连接到 telnet 服务器的脚本,执行一些通常的 telnet 操作,然后注销?我正在与不熟悉 telnet 和他们需要运行的命令的用户打交道.我想要的只是让他们双击一个脚本,然后让该脚本自动为他们执行命令.
Does anyone know of an easy way to create a script that can connect to a telnet server, do some usual telnet stuff, and then log off? I am dealing with users who are not familiar with telnet and the commands they will need to run. All I want is for them to double-click on a script, and have that script automatically execute the commands for them.
您可能想知道,用户在什么平台上?"它们将在 Windows 和 Linux 上运行.可以接受 Perl、Java 或 Python 等语言的实现.我看到 Perl 有一个 Net:: Telnet 模块.有人用过吗?
You're probably wondering, "What platform are the users on?" They will be on both Windows and Linux. Implementations in languages like Perl, Java, or Python are acceptable. I see that Perl has a Net:: Telnet module. Has anyone used that?
我的理想解决方案是创建两个脚本文件.Windows 的 BAT 文件和 Linux 的 shell 脚本.虽然这会使双重维护成为一个问题,但这意味着我不必在每台机器上安装 Perl/Java/Python/etc....不幸的是,我还没有看到任何使用批处理文件或 shell 脚本自动执行 telnet 会话的方法.
My ideal solution would be to create two script files. a BAT file for windows, and a shell script for Linux. While this would make dual maintenance an issue, it would mean I wouldn't have to install Perl/Java/Python/etc... on every machine. Unfortunately, I have not seen any way to automate a telnet session with batch files or shell scripts.
谢谢.
推荐答案
Expect 就是为此而构建的,并且可以处理输入/输出以及超时等.请注意,如果您不是 TCL 粉丝,则有适用于 Perl/Python/Java 的 Expect 模块.
Expect is built for this and can handle the input/output plus timeouts etc. Note that if you're not a TCL fan, there are Expect modules for Perl/Python/Java.
上述页面表明维基百科Expect条目是一个有用的资源:-)
The above page suggests that the Wikipedia Expect entry is a useful resource :-)
这篇关于为 Telnet 会话创建脚本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!