Expect, telnet, frozen console.

From: Gavin McDonald (gavin_at_advanceforklift.com)
Date: 03/29/04


Date: Mon, 29 Mar 2004 19:47:53 GMT

Hi all.

I have Expect v5.38.0/tcl v8.4 on linux 2.4.20 - Slackware 9.0.

I have a simple task I wish to automate:
telnet into remote host, provide username/password, surrender control to
user. This script will eventually be tied into /etc/inittab so that it
can be run in multiple consoles. (Another question in its own time.) The
script is called with a character and a tty as arguments. The script,
quoted below, works but hangs in a specific situation;

#!/usr/bin/expect --
log_user 0
set stty_init "sane cs8 -istrip"
spawn -nottycopy -nottyinit telnet $HOST
set tty_spawn_id /dev/[lrange $argv 1 1]
expect login
send "$USER[lrange $argv 0 0]\r"
expect Password
send "$PASSWORD\r"
log_user 1
interact eof

For each $USER on $HOST there are [a..j] logins, named [$USERa..$USERj].
the command:
# autologin b tty2
logs in to $HOST as $USERb. the .profile for said user starts a custom
app called 'loe' which presents a login screen in 80x24 ASCII a la
ncurses. (NOT ncurses tho...) from this point, I can login, use the app,
and all the f-keys, CTRL sequences etc work fine. To back out of a
screen, the user presses ESC, which also works fine. However, when the
user presses ESC to back out of the main menu, to the login screen, All
I/O stops. The cursor disappears, and no further input is accepted. The
processes stay active however, and if I 'kill -HUP' the telnet process,
expect exits cleanly. If I telnet manually to the host, this problem
does not happen at all.

I have compared the output of 'env' for the telnet, and the expect
logins, and they are identical. It is as though the "login" screen that
is displayed sends a control character which takes expect out of the
"interact" command.

I have, on occasion, been able to avoid this by pressing ESC twice, (or
ESC,ENTER) with enough speed that they transmit before the screen
redraws. I have also tried removing "eof" from interact, but still the
problem persists.

The "set stty_init ..." line is an attempt to solve the problem as was
done here: http://tinyurl.com/ytpse which met with limited, (though
unrepeatable,) success. The line "set tty_spawn_id" was yet another
attempt to fix the problem, again unsuccessfully. (Now I leave it as an
artifact for adding the aforementioned virtual terminal support.)

I now turn to the sages at c.l.t in hopes that someone has seen this
before, or knows where to turn.

One last thing: I have been in contact with tier 1 support for the
'loe' people, and they were unable/unwilling to furnish further details
on the output of their login screen.

Thanks for your help,
Gavin McDonald.



Relevant Pages

  • Re: Script for telnet server to communicate with J2EE application
    ... Is there any way that this script automatically get invoked as the ... Telnet Client login to Server? ... As you were asking about using telnet client classes to allow your Java application to talk to a telnet server, I was assuming you'd want to use something like the following to login, send one barcode to the telnet server and logout again: ...
    (comp.lang.java.programmer)
  • Re: rlogin
    ... login the server using telnet, rsh, rlogin and also ssh. ... Telnet does not provide any protection. ... We have only 1 host system. ...
    (comp.unix.aix)
  • Re: Need help sending a password to ftp
    ... > then bring up ftp on that system to transfer some files over there. ... > can get the telnet session open. ... The script fails with: ... > 530 Login incorrect. ...
    (comp.lang.perl.misc)
  • Need help sending a password to ftp
    ... I need to create a perl/expect script that will telnet into a system ... then bring up ftp on that system to transfer some files over there. ... 530 Login incorrect. ...
    (comp.lang.perl.misc)
  • Problems getting ftp to take my password
    ... I need to create a perl/expect script that will telnet into a system ... then bring up ftp on that system to transfer some files over there. ... 530 Login incorrect. ...
    (comp.lang.perl.modules)