1753488 Members
4118 Online
108794 Solutions
New Discussion

Expect/TCL Help!

 
Surey
Occasional Advisor

Expect/TCL Help!

Hello TCL Gurus,

 

I am using an Expect/TCL script to change HP-UX console passwords. The script works for rx2660, rx3600 & rx7640 type consoles. However it fails for a rx2800 type console.

 

Here it fails soon after logging in:

   MP MAIN MENU:

         CO: Console
        VFP: Virtual Front Panel
         CM: Command Menu
         CL: Console Log
         SL: Show Event Logs
         HE: Main Help Menu
          X: Exit Connection

[cons-mlxg0d02]</> hpiLO->

 

 

 

Here are the error messages from the scipt. The line in red shows where the failure is. The rest are the remaining error messages:

password not changed on xxx.xxx.xxx.xxx - could not log in (or unrecognized prompt)

invoked "continue" outside of a loop
    while executing
"expect -re "(login|Username):.*" {
send "$user\r"

if ![info exists prompt] {
        if {[ string match $user "root" ]} {
            set prompt "# "
        } else {
          ..."
    (file "./passlans_cmdline" line 79)
mlxg0s15:/home/sselva/TCL #

 

 

 

 

My gut instinct tells me that the failure is taking place at the line below underlined and in red:

expect -re "(login|Username):.*" {
send "$user\r"

if ![info exists prompt] {
        if {[ string match $user "root" ]} {
            set prompt "# "
        } else {
            set prompt "(%|\\\$|#|GSP\>|MP\>|Root\>) "
        }
    }

    set logged_in 0
    while {1} {
        expect "*assword*" {
            # If it asks for password, send the password followed by the signals
 for both
            # the RP-5470 (ctrl-Ecf) and the later MP (ctrl-B) to send either to
 the active
            # main menu.
            send "$password(login)\r^Ecf\n\n^B"
        } eof {
            badhost $host "spawn failed"
            break
        } timeout {
            badhost $host "could not log in (or unrecognized prompt)"
            exec kill $pid
            expect eof
            break
        } -re "incorrect|invalid|login:" {
            badhost $host "bad password or login"
            exec kill $pid
            expect eof
            break
        } -re $prompt {
            set logged_in 1
            break
        }
    }

    if (!$logged_in) {
        wait
        continue
    }

 

 

 

Can some of you TCL gurus let me kow the following?

  1. If the problem is at the "send $password" line in red?
  2. If so what should the correct string of chjaracters be?

All helpful responses will be greatly appreciated?

 

Thanks in Advance,

Suren S.

Knowledge is power!
3 REPLIES 3
Patrick Wallek
Honored Contributor

Re: Expect/TCL Help!

It appears that it is having problems matching a prompt somewhere in the output you are getting.

 

Try running your program with the '-d' option.

 

For example:

 

# expect -d myprogram

 

Then check the output and see where your failure to match is occurring.

Surey
Occasional Advisor

Re: Expect/TCL Help!

When I ran expect with the "-d" option, I got the following response:

password not changed on 10.1.16.102 - could not log in (or unrecognized prompt)


expect: does "" (spawn_id exp0) match glob pattern "\u0003"? no
expect: read eof
expect: set expect_out(spawn_id) "exp6"
expect: set expect_out(buffer) "********\r\n\r\n\r\n         Hewlett-Packard Integrated Lights-Out 3 for Integrity\r\n\r\n  (C) Copyright 1999-2010 Hewlett-Packard Development Company, L.P.\r\n\r\n                    MP Host Name: cons-mlxg0d02\r\n\r\n                 iLO MP Firmware Revision 01.30.30\r\n\r\n\n   MP MAIN MENU:\r\n\n         CO: Console\r\n        VFP: Virtual Front Panel\r\n         CM: Command Menu\r\n         CL: Console Log\r\n         SL: Show Event Logs\r\n         HE: Main Help Menu\r\n          X: Exit Connection\r\n\n[cons-mlxg0d02]</> hpiLO-> "
write() failed to write anything - will sleep(1) and retry...
invoked "continue" outside of a loop
    while executing
"expect -re "(login|Username):.*" {
send "$user\r"

if ![info exists prompt] {
        if {[ string match $user "root" ]} {
            set prompt "# "
        } else {
          ..."
    (file "./passlans_cmdline" line 79)
tty_set: raw = 5, echo = 0
mlxg0s15:/home/sselva/TCL #

 

 

 

I have only included the last part after the failure. Doea any of this make sense?

 

-Suren

Knowledge is power!
Patrick Wallek
Honored Contributor

Re: Expect/TCL Help!

Can you attach the complete run of the expect script so that we can see what occurred before the error message as well?