简体   繁体   English

使用Shellscript(OSX)和Expect进行Telnet

[英]Telnet by using Shellscript (OSX) with Expect

I want to connect a machine by telnet. 我想通过telnet连接机器。 Attempting to use Expect is not working. 尝试使用Expect不起作用。 There is no username and password. 没有用户名和密码。 Here is where I'm at. 这是我的位置。

#!/usr/bin/expect -f

Echo Hello World
telnet IP_Address_Here 10001

expect "]'."
send "^a200\r"

This works up to the 'expect'. 这符合“期望”。 This is the result of the code... 这是代码的结果...

Roberts-MacBook:~ rameeti$ sh test.sh
Hello World
Trying IP_Address_Here...
Connected to IP_Address.lightspeed.irvnca.sbcglobal.net.
Escape character is '^]'.

And then it sits waiting for the command that I want to send: "^a200" Why is the 'expect' not working? 然后它等待我要发送的命令:“ ^ a200”为什么“期望”不起作用?

I guess you are executing it with bash instead of expect . 我猜你与执行它bash ,而不是expect

Otherwise, you will receive 否则,您会收到

invalid command name "Echo"
    while executing
"Echo Hello World"

try 尝试

$ expect -f test.sh

BTW, you should not name it .sh if it's expect. 顺便说一句,如果期望的话,您不应将其命名为.sh

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM