skip to Main Content

I am running CentOS 7.6

$ cat /etc/system-release
CentOS Linux release 7.6.1810 (Core)

This is the most recent version of expect from the repos.

$ expect -version
expect version 5.45

As per your suggestion, I have adjusted my code to make this easier to fix, the authentication part should not be a problem so I removed it for now, below is my expect code, testing a device that does not have authentication.

$ cat runCommands.exp
spawn telnet 10.220.64.67
set prompt "#"
expect ">"
send "enabler"
expect $prompt
send "terminal length 200r"
expect $prompt
send "terminal more offr"
expect $prompt
send "show hw-inventory detailsr"
expect $prompt
send "exitr"
expect eof

This is how I am running my expect script, it starts correctly but at the end it just stops.

$ expect -f ./runCommands.exp
spawn telnet 10.220.64.67
Trying 10.220.64.67...
Connected to 10.220.64.67.
Escape character is '^]'.

******************************************************************
*                                                                *
*                  Tellabs 8609 Network Element                  *
*                                                                *
*     Copyright (c) 2004-2015 Tellabs. All rights reserved.      *
*                                                                *
******************************************************************
Enter configuration commands, one per line. End with ^Z
HENKEL_CAPITAL_2-EQU>enable
HENKEL_CAPITAL_2-EQU#terminal length 200
HENKEL_CAPITAL_2-EQU#terminal more off
HENKEL_CAPITAL_2-EQU#show hw-inventory details
This is node 1643 of type 8609 and subrack address 0.
    unit in slot 1 is part of inventory and UP AND RUNNING
        unit 1 of width 1 has serial number 40601444713, CLEI code IPMVU00DRB
        top level serial number 40601445792
        manufacturing date 2016-3-30, 4:42:19.0, +0:00
        part# 82.86S-8609-R6 rev C
        HW type sbb2284-8609(2284) v3.0.1 SW type 0 v2.0.331
            Pmax=70.0W, Ptyp=60.0W
        infomodel FP2.0 (2.2.0); internal SW v.2.0.331
            Supported infomodels:
                FP2.0 (2.2.0)
        CPLD active revision: 0x0130
        WPIF expected and active revision: 0x001a
        LMIF expected and active revision: 0x0023
        TOCK expected and active revision: 0x0416
        module IF0 (LEFT) of type 4*100/1000BASE-X(9094)
            SFP connector 0 data:
                [0] type of serial transceiver: 3 (SFP transceiver)
                [1] extended identifier of type of serial transceiver: 4
                [2] connector type: 7(LC)
                [3] infiniband compliance code: 0
                [4] sonet compliance code4: 0
                [5] sonet compliance code5: 0
                [6] gigabit ethernet compliance code: 2, 1000BASE-LX
                [11] serial encoding type: 1 8B10B
                [14] link length for 9/125mm fiber (km): 52
                [15] link length for 9/125mm fiber (100m): 255
                [16] link length for 50/125mm fiber (10m): 0
                [17] link length for 62.5/125mm fiber (10m): 0
                [18] link length for copper (m): 0
                [20] vendor name: FINISAR CORP.
                [37] vendor organizationally unique: 36965
                [40] vendor part number: FTLF1419P1BCL-TL
                [56] vendor revision number: A
                [60] Laser wavelength: 1310 nm
                [62] reserved field: 0
                [68] vendor serial number: PU117T5
                [84] vendor's date (yy-mm-dd): 15-07-03
                [90] vendor's date (vendor specific part):
                [224-241] Tellabs part number: 81.86T-S001-13S-R6
                [242-243] Tellabs revision:  A
                [244-253] Tellabs CLEI code:  IPU3AVSKAA
                [255] Tellabs checksum: 0x3C
                [d102] Tx power: 2.6 dBm (1.8 mW)
                [d104] Rx power: -7.8 dBm (0.17 mW)
            SFP connector 1 is not present
            SFP connector 2 is not present
            SFP connector 3 is not present
        module IF1 (MIDDLE LEFT) of type 4*100/1000BASE-X(9094)
            SFP connector 0 data:
                [0] type of serial transceiver: 3 (SFP transceiver)
                [1] extended identifier of type of serial transceiver: 4
                [2] connector type: 7(LC)
                [3] infiniband compliance code: 0
                [4] sonet compliance code4: 0
                [5] sonet compliance code5: 0
                [6] gigabit ethernet compliance code: 2, 1000BASE-LX
                [11] serial encoding type: 1 8B10B
                [14] link length for 9/125mm fiber (km): 40
                [15] link length for 9/125mm fiber (100m): 0
                [16] link length for 50/125mm fiber (10m): 0
                [17] link length for 62.5/125mm fiber (10m): 0
                [18] link length for copper (m): 0
                [20] vendor name: HG GENUINE
                [37] vendor organizationally Connection closed by foreign host.

As you can see above, the error I am getting is Connection closed by foreign host and I can not get the full output of the show hw-inventory details command, not sure if the size of the output could be affecting this.

As the only resource I know for debugging this expect script is adding the -d flag I have run exactly the same script with that option in case we can get an idea about what is going on here.

$ expect -df ./runCommands.exp
expect version 5.45
argv[0] = expect  argv[1] = -df  argv[2] = ./runCommands.exp
set argc 0
set argv0 "./runCommands.exp"
set argv ""
executing commands from command file ./runCommands.exp
spawn telnet 10.220.64.67
parent: waiting for sync byte
parent: telling child to go ahead
parent: now unsynchronized from child
spawn: returns {15767}

expect: does "" (spawn_id exp6) match glob pattern ">"? no
Trying 10.220.64.67...

expect: does "Trying 10.220.64.67...rrn" (spawn_id exp6) match glob pattern ">"? no
Connected to 10.220.64.67.
Escape character is '^]'.

expect: does "Trying 10.220.64.67...rrnConnected to 10.220.64.67.rrnEscape character is '^]'.rrn" (spawn_id exp6) match glob pattern ">"? no

******************************************************************
*                                                                *
*                  Tellabs 8609 Network Element                  *
*                                                                *
*     Copyright (c) 2004-2015 Tellabs. All rights reserved.      *
*                                                                *
******************************************************************
Enter configuration commands, one per line. End with ^Z
HENKEL_CAPITAL_2-EQU>
expect: does "Trying 10.220.64.67...rrnConnected to 10.220.64.67.rrnEscape character is '^]'.rrnrrn******************************************************************rrn*                                                                *rrn*                  Tellabs 8609 Network Element                  *rrn*                                                                *rrn*     Copyright (c) 2004-2015 Tellabs. All rights reserved.      *rrn*                                                                *rrn******************************************************************rrnEnter configuration commands, one per line. End with ^ZrnHENKEL_CAPITAL_2-EQU>" (spawn_id exp6) match glob pattern ">"? yes
expect: set expect_out(0,string) ">"
expect: set expect_out(spawn_id) "exp6"
expect: set expect_out(buffer) "Trying 10.220.64.67...rrnConnected to 10.220.64.67.rrnEscape character is '^]'.rrnrrn******************************************************************rrn*                                                                *rrn*                  Tellabs 8609 Network Element                  *rrn*                                                                *rrn*     Copyright (c) 2004-2015 Tellabs. All rights reserved.      *rrn*                                                                *rrn******************************************************************rrnEnter configuration commands, one per line. End with ^ZrnHENKEL_CAPITAL_2-EQU>"
send: sending "enabler" to { exp6 }

expect: does "" (spawn_id exp6) match glob pattern "#"? no
HENKEL_CAPITAL_2-EQU>
expect: does "r                     u0008u0008u0008u0008u0008u0008u0008u0008u0008u0008u0008u0008u0008u0008u0008u0008u0008u0008u0008u0008u0008HENKEL_CAPITAL_2-EQU>" (spawn_id exp6) match glob pattern "#"? no
enable

expect: does "r                     u0008u0008u0008u0008u0008u0008u0008u0008u0008u0008u0008u0008u0008u0008u0008u0008u0008u0008u0008u0008u0008HENKEL_CAPITAL_2-EQU>enablern" (spawn_id exp6) match glob pattern "#"? no
HENKEL_CAPITAL_2-EQU#
expect: does "r                     u0008u0008u0008u0008u0008u0008u0008u0008u0008u0008u0008u0008u0008u0008u0008u0008u0008u0008u0008u0008u0008HENKEL_CAPITAL_2-EQU>enablernHENKEL_CAPITAL_2-EQU#" (spawn_id exp6) match glob pattern "#"? yes
expect: set expect_out(0,string) "#"
expect: set expect_out(spawn_id) "exp6"
expect: set expect_out(buffer) "r                     u0008u0008u0008u0008u0008u0008u0008u0008u0008u0008u0008u0008u0008u0008u0008u0008u0008u0008u0008u0008u0008HENKEL_CAPITAL_2-EQU>enablernHENKEL_CAPITAL_2-EQU#"
send: sending "terminal length 200r" to { exp6 }

expect: does "" (spawn_id exp6) match glob pattern "#"? no
terminal length 200

expect: does "terminal length 200rn" (spawn_id exp6) match glob pattern "#"? no
HENKEL_CAPITAL_2-EQU#
expect: does "terminal length 200rnHENKEL_CAPITAL_2-EQU#" (spawn_id exp6) match glob pattern "#"? yes
expect: set expect_out(0,string) "#"
expect: set expect_out(spawn_id) "exp6"
expect: set expect_out(buffer) "terminal length 200rnHENKEL_CAPITAL_2-EQU#"
send: sending "terminal more offr" to { exp6 }

expect: does "" (spawn_id exp6) match glob pattern "#"? no
terminal more off

expect: does "terminal more offrn" (spawn_id exp6) match glob pattern "#"? no
HENKEL_CAPITAL_2-EQU#
expect: does "terminal more offrnHENKEL_CAPITAL_2-EQU#" (spawn_id exp6) match glob pattern "#"? yes
expect: set expect_out(0,string) "#"
expect: set expect_out(spawn_id) "exp6"
expect: set expect_out(buffer) "terminal more offrnHENKEL_CAPITAL_2-EQU#"
send: sending "show hw-inventory detailsr" to { exp6 }

expect: does "" (spawn_id exp6) match glob pattern "#"? no
show hw-inventory details

expect: does "show hw-inventory detailsrn" (spawn_id exp6) match glob pattern "#"? no
This is node 1643 of type 8609 and subrack address 0.
    unit in slot 1 is pa
expect: does "show hw-inventory detailsrnThis is node 1643 of type 8609 and subrack address 0.rn    unit in slot 1 is pa" (spawn_id exp6) match glob pattern "#"? no
r
expect: does "show hw-inventory detailsrnThis is node 1643 of type 8609 and subrack address 0.rn    unit in slot 1 is par" (spawn_id exp6) match glob pattern "#"? no
t of inventory and UP AND RUNNING
        unit 1 of width 1 has serial number 4
expect: does "show hw-inventory detailsrnThis is node 1643 of type 8609 and subrack address 0.rn    unit in slot 1 is part of inventory and UP AND RUNNINGrn        unit 1 of width 1 has serial number 4" (spawn_id exp6) match glob pattern "#"? no
0601444713, CLEI code IPMVU00DRB
        top level serial number 40601445792
        manufacturing date 2016-3-30, 4:42:19.0, +0:00
        part# 82.86S-8609
expect: does "show hw-inventory detailsrnThis is node 1643 of type 8609 and subrack address 0.rn    unit in slot 1 is part of inventory and UP AND RUNNINGrn        unit 1 of width 1 has serial number 40601444713, CLEI code IPMVU00DRBrn        top level serial number 40601445792rn        manufacturing date 2016-3-30, 4:42:19.0, +0:00rn        part# 82.86S-8609" (spawn_id exp6) match glob pattern "#"? yes
expect: set expect_out(0,string) "#"
expect: set expect_out(spawn_id) "exp6"
expect: set expect_out(buffer) "show hw-inventory detailsrnThis is node 1643 of type 8609 and subrack address 0.rn    unit in slot 1 is part of inventory and UP AND RUNNINGrn        unit 1 of width 1 has serial number 40601444713, CLEI code IPMVU00DRBrn        top level serial number 40601445792rn        manufacturing date 2016-3-30, 4:42:19.0, +0:00rn        part#"
send: sending "exitr" to { exp6 }
-R6 rev C
        HW type sbb2284-8609(2284) v3.0.1 SW type 0 v2.0.331
            Pmax=70.0W, Ptyp=60.0W
        infomodel FP2.0 (2.2.0); internal SW v.2.0.331
            Supported infomodels:
                FP2.0 (2.2.0)
        CPLD active revision: 0x0130
        WPIF expected and active revision: 0x001a
        LMIF expected and active revision: 0x0023
        TOCK expected and active revision: 0x0416
        module IF0 (LEFT) of type 4*100/1000BASE-X(9094)
            SFP connector 0 data:
                [0] type of serial transceiver: 3 (SFP transceiver)
                [1] extended identifier of type of serial transceiver: 4
                [2] connector type: 7(LC)
                [3] infiniband compliance code: 0
                [4] sonet compliance code4: 0
                [5] sonet compliance code5: 0
                [6] gigabit ethernet compliance code: 2, 1000BASE-LX
                [11] serial encoding type: 1 8B10B
                [14] link length for 9/125mm fiber (km): 52
                [15] link length for 9/125mm fiber (100m): 255
                [16] link length for 50/125mm fiber (10m): 0
                [17] link length for 62.5/125mm fiber (10m): 0
                [18] link length for copper (m): 0
                [20] vendor name: FINISAR CORP.
                [37] vendor organizationally unique: 36965
                [40] vendor part number: FTLF1419P1BCL-TL
                [56] vendor revision number: A
                [60] Laser wavelength: 1310 nm
                [62] reserved field: 0
                [68] vendor serial number: PU117T5
                [84] vendor's date (yy-mm-dd): 15-07-03
                [90] vendor's date (vendor specific part):
                [224-241] Tellabs part number: 81.86T-S001-13S-R6
                [242-243] Tellabs revision:  A
                [244-253] Tellabs CLEI code:  IPU3AVSKAA
                [255] Tellabs checksum: 0x3C
                [d102] Tx power: 2.6 dBm (1.8 mW)
                [d104] Rx power: -7.7 dBm (0.17 mW)
            SFP connector 1 is not present
            SFP connector 2 is not present
            SFP connector 3 is not present
        module IF1 (MIDDLE LEFT) of type 4*100/1000BASE-X(9094)
            SFP connector 0 data:
                [0] type of serial transceiver: 3 (SFP transceiver)
                [1] extended identifier of type of serial transceiver: 4
                [2] connector type: 7(LC)
                [3] infiniband compliance code: 0
                [4] sonet compliance code4: 0
                [5] sonet compliance code5: 0
                [6] gigabit ethernet compliance code: 2, 1000BASE-LX
                [11] serial encoding type: 1 8B10B
                [14] link length for 9/125mm fiber (km): 40
                [15] link length for 9/125mm fiber (100m): 0
                [16] link length for 50/125mm fiber (10m): 0
                [17] link length for 62.5/125mm fiber (10m): 0
                [18] link length for copper (m): 0
                [20] vendor name: HG GENUINE
                [37] vendor organizationally unique: 0
                [40] vendor part number: MXPD-243MD
                [56] vendor revision number:
                [60] Laser wavelength: 1310 nm
                [62] reserved field: 0
                [68] vendor serial number: ME12112000011
                [84] vendor's date (yy-mm-dd): 12-03-17
                [90] vendor's date (vendor specific part):
                [224-255] vendor specific ID field : 0x00000000
                    0x00000000 0x00000000 0x00000000 0x00000000
                    0x00000000 0x00000000 0x00000000
                [d102] Tx power: -3.0 dBm (0.50 mW)
                [d104] Rx power: -13 dBm (50 uW)
            SFP connector 1 is not present
            SFP connector 2 is Connection closed by foreign host.
expect: read eof
expect: set expect_out(spawn_id) "exp6"
expect: set expect_out(buffer) " 82.86S-8609-R6 rev Crn        HW type sbb2284-8609(2284) v3.0.1 SW type 0 v2.0.331rn            Pmax=70.0W, Ptyp=60.0Wrn        infomodel FP2.0 (2.2.0); internal SW v.2.0.331rn            Supported infomodels:rn                FP2.0 (2.2.0)rn        CPLD active revision: 0x0130rn        WPIF expected and active revision: 0x001arn        LMIF expected and active revision: 0x0023rn        TOCK expected and active revision: 0x0416rn        module IF0 (LEFT) of type 4*100/1000BASE-X(9094)rn            SFP connector 0 data:rn                [0] type of serial transceiver: 3 (SFP transceiver)rn                [1] extended identifier of type of serial transceiver: 4rn                [2] connector type: 7(LC)rn                [3] infiniband compliance code: 0rn                [4] sonet compliance code4: 0rn                [5] sonet compliance code5: 0rn                [6] gigabit ethernet compliance code: 2, 1000BASE-LXrn                [11] serial encoding type: 1 8B10Brn                [14] link length for 9/125mm fiber (km): 52rn                [15] link length for 9/125mm fiber (100m): 255rn                [16] link length for 50/125mm fiber (10m): 0rn                [17] link length for 62.5/125mm fiber (10m): 0rn                [18] link length for copper (m): 0rn                [20] vendor name: FINISAR CORP.   rn                [37] vendor organizationally unique: 36965rn                [40] vendor part number: FTLF1419P1BCL-TLrn                [56] vendor revision number: A   rn                [60] Laser wavelength: 1310 nmrn                [62] reserved field: 0rn                [68] vendor serial number: PU117T5         rn                [84] vendor's date (yy-mm-dd): 15-07-03rn                [90] vendor's date (vendor specific part):   rn                [224-241] Tellabs part number: 81.86T-S001-13S-R6rn                [242-243] Tellabs revision:  A rn                [244-253] Tellabs CLEI code:  IPU3AVSKAArn                [255] Tellabs checksum: 0x3Crn                [d102] Tx power: 2.6 dBm (1.8 mW)rn                [d104] Rx power: -7.7 dBm (0.17 mW)rn            SFP connector 1 is not presentrn            SFP connector 2 is not presentrn            SFP connector 3 is not presentrn        module IF1 (MIDDLE LEFT) of type 4*100/1000BASE-X(9094)rn            SFP connector 0 data:rn                [0] type of serial transceiver: 3 (SFP transceiver)rn                [1] extended identifier of type of serial transceiver: 4rn                [2] connector type: 7(LC)rn                [3] infiniband compliance code: 0rn                [4] sonet compliance code4: 0rn                [5] sonet compliance code5: 0rn                [6] gigabit ethernet compliance code: 2, 1000BASE-LXrn                [11] serial encoding type: 1 8B10Brn                [14] link length for 9/125mm fiber (km): 40rn                [15] link length for 9/125mm fiber (100m): 0rn                [16] link length for 50/125mm fiber (10m): 0rn                [17] link length for 62.5/125mm fiber (10m): 0rn                [18] link length for copper (m): 0rn                [20] vendor name: HG GENUINE      rn                [37] vendor organizationally unique: 0rn                [40] vendor part number: MXPD-243MD      rn                [56] vendor revision number: rn                [60] Laser wavelength: 1310 nmrn                [62] reserved field: 0rn                [68] vendor serial number: ME12112000011   rn                [84] vendor's date (yy-mm-dd): 12-03-17rn                [90] vendor's date (vendor specific part):   rn                [224-255] vendor specific ID field : 0x00000000 rn                    0x00000000 0x00000000 0x00000000 0x00000000 rn                    0x00000000 0x00000000 0x00000000 rn                [d102] Tx power: -3.0 dBm (0.50 mW)rn                [d104] Rx power: -13 dBm (50 uW)rn            SFP connector 1 is not presentrn            SFP connector 2 is Connection closed by foreign host.rrn"

Do you think this could be an issue with the expect script itself or there could be something else related to the telnet device?

If you are willing to do so we can have a screen session and we can work together on this, at this point I feel desperate about this weird issue, not sure how to keep moving forward.

This is the full expected output:

$ telnet 10.220.64.67
Trying 10.220.64.67...
Connected to 10.220.64.67.
Escape character is '^]'.

******************************************************************
*                                                                *
*                  Tellabs 8609 Network Element                  *
*                                                                *
*     Copyright (c) 2004-2015 Tellabs. All rights reserved.      *
*                                                                *
******************************************************************
Enter configuration commands, one per line. End with ^Z
HENKEL_CAPITAL_2-EQU>enable
HENKEL_CAPITAL_2-EQU#show hw-inventory details
This is node 1643 of type 8609 and subrack address 0.
    unit in slot 1 is part of inventory and UP AND RUNNING
        unit 1 of width 1 has serial number 40601444713, CLEI code IPMVU00DRB
        top level serial number 40601445792
        manufacturing date 2016-3-30, 4:42:19.0, +0:00
        part# 82.86S-8609-R6 rev C
        HW type sbb2284-8609(2284) v3.0.1 SW type 0 v2.0.331
            Pmax=70.0W, Ptyp=60.0W
        infomodel FP2.0 (2.2.0); internal SW v.2.0.331
            Supported infomodels:
                FP2.0 (2.2.0)
        CPLD active revision: 0x0130
        WPIF expected and active revision: 0x001a
        LMIF expected and active revision: 0x0023
        TOCK expected and active revision: 0x0416
        module IF0 (LEFT) of type 4*100/1000BASE-X(9094)
            SFP connector 0 data:
                [0] type of serial transceiver: 3 (SFP transceiver)
                [1] extended identifier of type of serial transceiver: 4
                [2] connector type: 7(LC)
                [3] infiniband compliance code: 0
                [4] sonet compliance code4: 0
                [5] sonet compliance code5: 0
                [6] gigabit ethernet compliance code: 2, 1000BASE-LX
                [11] serial encoding type: 1 8B10B
                [14] link length for 9/125mm fiber (km): 52
                [15] link length for 9/125mm fiber (100m): 255
                [16] link length for 50/125mm fiber (10m): 0
                [17] link length for 62.5/125mm fiber (10m): 0
                [18] link length for copper (m): 0
                [20] vendor name: FINISAR CORP.
                [37] vendor organizationally unique: 36965
                [40] vendor part number: FTLF1419P1BCL-TL
                [56] vendor revision number: A
                [60] Laser wavelength: 1310 nm
                [62] reserved field: 0
                [68] vendor serial number: PU117T5
                [84] vendor's date (yy-mm-dd): 15-07-03
                [90] vendor's date (vendor specific part):
                [224-241] Tellabs part number: 81.86T-S001-13S-R6
                [242-243] Tellabs revision:  A
                [244-253] Tellabs CLEI code:  IPU3AVSKAA
                [255] Tellabs checksum: 0x3C
                [d102] Tx power: 2.6 dBm (1.8 mW)
                [d104] Rx power: -7.7 dBm (0.17 mW)
            SFP connector 1 is not present
            SFP connector 2 is not present
            SFP connector 3 is not present
        module IF1 (MIDDLE LEFT) of type 4*100/1000BASE-X(9094)
            SFP connector 0 data:
                [0] type of serial transceiver: 3 (SFP transceiver)
                [1] extended identifier of type of serial transceiver: 4
                [2] connector type: 7(LC)
                [3] infiniband compliance code: 0
                [4] sonet compliance code4: 0
                [5] sonet compliance code5: 0
                [6] gigabit ethernet compliance code: 2, 1000BASE-LX
                [11] serial encoding type: 1 8B10B
                [14] link length for 9/125mm fiber (km): 40
                [15] link length for 9/125mm fiber (100m): 0
                [16] link length for 50/125mm fiber (10m): 0
                [17] link length for 62.5/125mm fiber (10m): 0
                [18] link length for copper (m): 0
                [20] vendor name: HG GENUINE
                [37] vendor organizationally unique: 0
                [40] vendor part number: MXPD-243MD
                [56] vendor revision number:
                [60] Laser wavelength: 1310 nm
                [62] reserved field: 0
                [68] vendor serial number: ME12112000011
                [84] vendor's date (yy-mm-dd): 12-03-17
                [90] vendor's date (vendor specific part):
                [224-255] vendor specific ID field : 0x00000000
                    0x00000000 0x00000000 0x00000000 0x00000000
                    0x00000000 0x00000000 0x00000000
                [d102] Tx power: -3.0 dBm (0.50 mW)
                [d104] Rx power: -13 dBm (50 uW)
            SFP connector 1 is not present
            SFP connector 2 is not present
            SFP connector 3 is not present
        module IF2 (MIDDLE) of type 4*10/100/1000BASE-T(9093)
        module IF3 (RIGHT MIDDLE) of type 8*10/100BASE-TX-LM(2243) v2.0.1 (hot insert)
            serial number 40601373354, CLEI code IPU3A7TKAA
            top level serial number 40601376329
            manufacturing date 2015-10-20, 8:51:59.0, +0:00
            part# 81.86LFETX82243-R6 rev D
            Pmax=4.60W, Ptyp=4.00W
        module IF4 (RIGHT) of type 8*10/100BASE-TX-LM(2243) v2.0.1 (hot insert)
            serial number 40601405399, CLEI code IPU3A7TKAA
            top level serial number 40601405948
            manufacturing date 2015-12-31, 0:06:43.0, +0:00
            part# 81.86LFETX82243-R6 rev D
            Pmax=4.60W, Ptyp=4.00W
        module COOLING FAN 1 of type fmb2285-coolingFan(2285)
        module PRIMARY POWER of type -48Vdc(2264)(2264) v2.0.0
            serial number 40601425507, CLEI code IPUPAKMLAA
            top level serial number 40601430234
            manufacturing date 2016-2-26, 17:02:48.9, +8:00
            part# 81.86P-0911DC48-R6 rev C
            Pmax=0.00W, Ptyp=0.00W
        module OVEN CONTROLLED OSCILLATOR of type vid9096-ocxo(9096) v1.0.0
        interface module 0 has
            expected type 4*100/1000BASE-X
            active   type 4*100/1000BASE-X
            existing type 4*100/1000BASE-X
            mode is not relevant
        interface module 1 has
            expected type 4*100/1000BASE-X
            active   type 4*100/1000BASE-X
            existing type 4*100/1000BASE-X
            mode is not relevant
        interface module 2 has
            expected type 4*10/100/1000BASE-T
            active   type 4*10/100/1000BASE-T
            existing type 4*10/100/1000BASE-T
            mode is not relevant
        interface module 3 has
            expected type 8*10/100BASE-TX-LM
            active   type 8*10/100BASE-TX-LM
            existing type 8*10/100BASE-TX-LM
            mode is not relevant
            Pmax=4.60W, Ptyp=4.00W
        interface module 4 has
            expected type 8*10/100BASE-TX-LM
            active   type 8*10/100BASE-TX-LM
            existing type 8*10/100BASE-TX-LM
            mode is not relevant
            Pmax=4.60W, Ptyp=4.00W
        power module primary has
            expected type -48Vdc(2264)
            active   type -48Vdc(2264)
            existing type -48Vdc(2264)
            mode is not relevant
            Pmax=0.00W, Ptyp=0.00W
        oven controlled oscillator has
            expected type vid9096-ocxo
            active   type vid9096-ocxo
            existing type vid9096-ocxo
            mode is not relevant

HENKEL_CAPITAL_2-EQU#exit
Connection closed by foreign host.

In the previous output, I entered the commands manually and it worked correctly the only difference is that I did not use the terminal more off and terminal length 200 commands.

$ telnet 10.220.64.67
Enter configuration commands, one per line. End with ^Z
HENKEL_CAPITAL_2-EQU>enable
HENKEL_CAPITAL_2-EQU#show hw-inventory details
**[short output... due to the limit of the stackoverflow text box]**
--More--
            mode is not relevant
HENKEL_CAPITAL_2-EQU#exit
Connection closed by foreign host.

When I see the –More– string I just type the space bar in order to get more output until the last prompt HENKEL_CAPITAL_2-EQU# is shown, then I just type the exit command.

2

Answers


  1. Your main problem seems to be that you are interleaving code (especially those sleep 1s!) at different levels, resulting in a script that’s actually pure gibberish. That the code isn’t crashing is pure happenstance.

    Rewriting the section with the problems while taking a guess as to what you need…

    # Handle login
    expect {
        "user name:" {
            send "$userr"
            exp_continue; # keep waiting
        }
        "password:" {
            send "$passwordr"
            exp_continue; # keep waiting
        }
        ">" {
            # Got a logged-in prompt so stop waiting (by not exp_continuing)
        }
    }
    
    # Handle what's going on remotely; note that we've a prompt at this point
    # and can use simple challenge/response coding from here on
    set prompt "# "
    send "enabler"
    expect $prompt
    send "terminal length 200r"
    expect $prompt
    send "terminal more offr"
    foreach cmd $commands {
        expect $prompt
        send "$cmdr"
    }
    expect $prompt
    send "exitr"
    expect eof
    

    This technique becomes more valuable once you add in error handling rather than trusting everything to work, as one of the main powers of expect is being able to wait for several things at once. You don’t usually need that, but it’s super-valuable when you do!

    You don’t normally need to add in sleep calls, not when you’re just sending a command an waiting for the prompt back.

    Login or Signup to reply.
  2. The problem is in here:

    send "show hw-inventory detailsr"
    expect $prompt
    send "exitr"
    

    You set prompt "#" which is very dangerous. The output of show hw-inventory details does have the char # (see the line part# 82.86S-8609-R6 rev C) so expect $prompt would succeed and then it send "exitr" and so the connection is closed.

    Solution: Use a more accurate string for the prompt, for example:

    # '[' needs to be backslash escaped or it'll trigger Tcl's command substitution
    set prompt "HENKEL_CAPITAL_2-EQU[>#]"
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search