[HPADM] SUMMARY: Trouble Using Expect to Telnet from HP-UX 11.00 to Windows

From: Dave T. (davidlt77@hotmail.com)
Date: Thu Oct 16 2003 - 11:48:26 EDT


Shyam provided a workable solution with his attached script. I was able to
modify his script to accomplish my purposes. My original post is at the end
of this message. Following is the script I'm now using:

#!/usr/local/bin/expect -f

set force_conservative 1 ;# set to 1 to force conservative mode even if
                          ;# script wasn't run conservatively originally
if {$force_conservative} {
        set send_slow {1 .1}
        proc send {ignore arg} {
                sleep .1
                exp_send -s -- $arg
        }
}

set timeout 3
spawn $env(SHELL)
match_max 100000
send -- "telnet <server> 1023\r"
expect
send -- ""
expect
send -- "mode character\r"
expect
send -- "<logon>\r"
expect
send -- "<password>\r"
expect
send -- "startapp.bat\r"
expect
sleep 60
send -- "exit"
expect

Dave

----Original Message Follows----
From: "Hazari Shyam (WQQ1SXH)" <WQQ1SXH@ups.com>
To: "'Dave T.'" <davidlt77@hotmail.com>
Subject: RE: [HPADM] Trouble Using Expect to Telnet from HP-UX 11.00 to
Windows
Date: Thu, 16 Oct 2003 08:49:23 -0400

Dave,

Here is a sample script I used to download brocade switch config. Let me
know if you have any questions.

Thanx

-Shyam

-----Original Message-----
From: Dave T. [mailto:davidlt77@hotmail.com]
Sent: Wednesday, October 15, 2003 1:43 PM
To: hpux-admin@DutchWorks.nl
Subject: [HPADM] Trouble Using Expect to Telnet from HP-UX 11.00 to Windows

I'm hoping someone on the HP-UX list has enough experience with expect to
point me in the correct direction. I wrote an expect script to do the
following:

1. Telnet from HP-UX 11.00 to Windows.
2. Execute a script on the Windows server and exit.

I posted the following on a newsgroup for expect, and I didn't get any
responses:

I've written the expect script below:

#!/usr/local/bin/expect -b

exp_internal 1

set timeout 10

spawn telnet server 1023
expect "login: "
send ""
expect "telnet> "
send "mode character\r\r"
expect "login: "
send "krservice\r"
expect "password: "
send "abcdefg\r"
expect "D:\RemoteScript>"
send "stopapp.bat\r"
wait
expect "D:\RemoteScript>"
send "exit\r"

exit

This script produces the following:

spawn telnet server 1023
parent: waiting for sync byte
parent: telling child to go ahead
parent: now unsynchronized from child
spawn: returns {27301}

expect: does "" (spawn_id exp5) match glob pattern "login: "? no Trying...

expect: does "Trying...\r\n" (spawn_id exp5) match glob pattern
"login: "? no
Connected to server.
Escape character is '^]'.

expect: does "Trying...\r\nConnected to server.\r\nEscape character is
'^]'.\r\n" (spawn_id exp5) match glob pattern "login: "? no Microsoft (R)
Windows (TM) Version 5.00 (Build 2195) Welcome to Microsoft Telnet Service
Telnet Server Build 5.00.992
expect: does "Trying...\r\nConnected to server.\r\nEscape character is
'^]'.\r\nMicrosoft (R) Windows (TM) Version 5.00 (Build 2195)\r\r\nWelcome
to Microsoft Telnet Service \r\r\nTelnet Server Build 5.00.992" (spawn_id
exp5) match glob pattern "login: "? no 06.1
login:
expect: does "Trying...\r\nConnected to server.\r\nEscape character is
'^]'.\r\nMicrosoft (R) Windows (TM) Version 5.00 (Build 2195)\r\r\nWelcome
to Microsoft Telnet Service \r\r\nTelnet Server Build
5.00.99206.1\r\n\rlogin: " (spawn_id exp5) match glob pattern
"login: "? yes
expect: set expect_out(0,string) "login: "
expect: set expect_out(spawn_id) "exp5"
expect: set expect_out(buffer) "Trying...\r\nConnected to server.\r\nEscape
character is '^]'.\r\nMicrosoft (R) Windows (TM) Version 5.00 (Build
2195)\r\r\nWelcome to Microsoft Telnet Service \r\r\nTelnet Server Build
5.00.99206.1\r\n\rlogin: "
send: sending "\u001d" to { exp5 }

expect: does "" (spawn_id exp5) match glob pattern "telnet> "? no

expect: does "\n" (spawn_id exp5) match glob pattern "telnet> "? no
telnet>
expect: does "\ntelnet> " (spawn_id exp5) match glob pattern "telnet> "? yes
expect: set expect_out(0,string) "telnet> "
expect: set expect_out(spawn_id) "exp5"
expect: set expect_out(buffer) "\ntelnet> "
send: sending "mode character\r\r" to { exp5 }

expect: does "" (spawn_id exp5) match glob pattern "login: "? no mode
character

expect: does "mode character\r\n\r\n" (spawn_id exp5) match glob pattern
"login: "? no
expect: timed out
send: sending "krservice\r" to { exp5 }

expect: does "mode character\r\n\r\n" (spawn_id exp5) match glob pattern
"password: "? no ioctl error on TIOCREQCHECK: invalid argument
     while executing
"expect "password: "
"

Obviously, the script isn't working. What am I doing wrong?

Also, if anyone has a working autoexpect script on HP-UX, please send it to
me. The one I have doesn't work.

Thnx,

Dave

_________________________________________________________________
Page a contact’s mobile phone with MSN Messenger 6.0. Download it now FREE!
   http://msnmessenger-download.com


--
             ---> Please post QUESTIONS and SUMMARIES only!! <---
        To subscribe/unsubscribe to this list, contact majordomo@dutchworks.nl
       Name: hpux-admin@dutchworks.nl     Owner: owner-hpux-admin@dutchworks.nl
 
 Archives:  ftp.dutchworks.nl:/pub/digests/hpux-admin       (FTP, browse only)
            http://www.dutchworks.nl/htbin/hpsysadmin   (Web, browse & search)



This archive was generated by hypermail 2.1.7 : Sat Apr 12 2008 - 11:02:35 EDT