Reputation: 1141
I need to replace a very simple expect
script that looks like this:
#!/usr/bin/expect
spawn telnet 192.168.1.175
expect {
"assword" {send "lamepassword\r"}
}
interact
With the equivalent bash
script using empty
, like this:
#!/bin/bash
empty -f -i in -o out telnet 192.168.1.175
empty -w -i out -o in "assword" "lamepassword\n"
After which I need the user to interact
with telnet, which I do not know how to do. The closest thing that comes to my mind is binding stdin
and stdout
with named pipes
using something like socat - in
. Any suggestions are more than welcome!
Upvotes: 1
Views: 359
Reputation: 19375
I tried
cat out & cat /dev/stdin >in
, it works, but it has an extra newline, tab completion does not work andctr+c
terminatescat
and not the running host process. I am trying to persuadesocat
to act according to those needs.
Using socat
for transmitting keyboard input to the telnet
process is a good idea. Example:
cat out & socat -u -,raw,echo=0 ./in
For allowing Ctrl
-C
to terminate socat
, add escape=3
:
cat out & socat -u -,raw,echo=0,escape=3 ./in
But note that this will not terminate the telnet
session, since it did start in daemon mode, so you can reconnect to telnet
by executing socat
again. To end telnet
, you could just logout
.
Upvotes: 1