Solo has asked for the wisdom of the Perl Monks concerning the following question:

I'm not sure what info is relevant here, so this may be a little verbose. I am trying to use Net::Telnet from:

perl, v5.8.0 built for sun4-solaris SunOS 5.8 Generic_108528-15 sun4u sparc SUNW,Ultra-250

to

HP-UX B.11.11 U 9000/800 (tc)

with the simple script

my $t = new Net::Telnet (Timeout => 30, Prompt => '/[:\$%#>] $/'); $t->input_log(\*STDOUT); $t->telnetmode(1); $t->open($hostip); $t->login($user, $pass);

Logon works. My problem is that after logon, the expected prompt doesn't show up in the input (which is the output of the remote server). Rather, I get a strange escape sequence like:

.^[ i^M ... ^M.^[* ... ^MTERM = (hp)

I'm supposing this is a control stream, but I can't find any reference to handling them in Net::Telnet except for telnetmode() which I explicitly turn on. (Turning it off causes logon to fail.) Prompt on the remote host is '$'.

Anyone see what I'm doing wrong, or how I can workaround the problem? TIA!

P.S. I would try Expect, but unfortunately it is not available everywhere I need to use this.

--Solo
--
You said you wanted to be around when I made a mistake; well, this could be it, sweetheart.

Replies are listed 'Best First'.
Re: Net::Telnet problem w/ escape sequences (control stream?)
by sweetblood (Prior) on Jun 16, 2004 at 17:59 UTC
    on my HP-UX ----- B.11.11 U 9000/800 I run the above code and have no problem. I suspect your trouble may be related to the .profile of the $user. The section of my .profile that sets up the term is as follows:
    # Set up the terminal: if [ "$TERM" = "" ] then eval ` tset -s -Q -m ':?hp' ` else eval ` tset -s -Q ` fi stty erase "^H" kill "^U" intr "^C" eof "^D" susp "^Z" stty hupcl ixon ixoff tabs
    HTH

    Cheers

    Sweetblood

      Cool suggestion! I looked in the .profile (and .login) and saw the tset and stty commands as expected.

      I dug around and found another HPUX box to test on. This one worked. Adding a print $t->cmd('uname -a'); to my snippet above gets me:

      ... login garbage ... .^[ i^M ^M.^[[ci^M ^M.^[*s1^^Qi^M ^M$ HP-UX --- B.11.00 U 9000/785 (tc)

      I see similar control sequences, but this one ends in the expected prompt, '$'.

      So I changed the prompt string to '/(?:TERM = \(hp\)|[:%\$#])\s?$/' and it's working on the first server now.

      I need to figure out why under Net::Telnet's connection, the prompt is not being set properly. From /usr/bin/telnet I see '$' on both servers.

      --Solo
      --
      You said you wanted to be around when I made a mistake; well, this could be it, sweetheart.

        those are escape characters (bold,colors,etc) and the holdup is tset asking you to confirm the terminal type (hp)

        # probably looks like tset ?hp # remove question mark to accept hp always tset hp # choose dumber terminal type to possibly rid self of those # nasty escape sequences tset dumb tset ansi