Automatically entering text in telnet from mac

Viewed 65

I'm trying to write a script to send a simple text string (rprst 2 $0D) over telnet from a mac running OS 10.11 to a legacy embedded device. SSH is not an option. There is no password to get in to the device.

#!/usr/bin/expect -f
telnet 172.16.1.10
sleep 1
expect "'^]'"
sleep 1
echo RPRST 2 $0D

When I run this, the system logs into the telnet session, then stops. I can enter [CTRL] + ] then quit, at which point I get a 1 second pause, then the following:

Connection closed.
couldn't read file ""'^]'"": no such file or directory

"rprst 2 /Users/$USR/Desktop/my_script.shD"

I've also tried a header of #!/bin/bash and tried system instead of expect. I have also tried removing or changing my sleep times, removing the double quotes from the Expect line. I tried using "spawn telnet", but Mac is telling me that spawn is not a valid command. Does anyone have any ideas?

EDIT: I've kept trying, with no success. My latest attempt:

#!/bin/sh
{ echo "rprst 2 $0D"; sleep 1; echo "rprst 2 $0D"; sleep 1; } | telnet 172.16.1.10 23

the Terminal gives me the response:

Trying 172.16.1.10...
Connected to 172.16.1.10.
Escape character is '^]'.

telnet> ?Invalid command
telnet> Connection closed.
0 Answers
Related