Linux ожидаемый сценарий, иногда заканчивающийся `Соединение закрыто сторонним хостом`, это ожидаемый сценарий или проблема с устройством? - PullRequest
0 голосов
/ 15 февраля 2020

Я использую CentOS 7.6

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

Это самая последняя версия ожидания от репозиториев.

$ expect -version
expect version 5.45

Согласно вашему предложению, я изменил свой код, чтобы сделать это легче исправить, часть аутентификации не должна быть проблемой, поэтому я удалил ее сейчас, ниже приведен мой ожидаемый код, тестирующий устройство без аутентификации.

$ cat runCommands.exp
spawn telnet 10.220.64.67
set prompt "#"
expect ">"
send "enable\r"
expect $prompt
send "terminal length 200\r"
expect $prompt
send "terminal more off\r"
expect $prompt
send "show hw-inventory details\r"
expect $prompt
send "exit\r"
expect eof

Вот как я работаю Мой ожидаемый сценарий, он запускается правильно, но в конце он просто останавливается.

$ 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.

Как вы можете видеть выше, я получаю ошибку Соединение закрыто сторонним хостом , и я могу не удалось получить полный вывод команды show hw-inventory details , не уверен, что размер выходных данных может повлиять на это.

Как единственный ресурс, который я знаю для отладки этого сценария ожидаемого добавляет флаг -d Я запустил точно такой же сценарий с этой опцией на случай, если мы сможем получить представление о том, что здесь происходит.

$ 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...\r\r\n" (spawn_id exp6) match glob pattern ">"? no
Connected to 10.220.64.67.
Escape character is '^]'.

expect: does "Trying 10.220.64.67...\r\r\nConnected to 10.220.64.67.\r\r\nEscape character is '^]'.\r\r\n" (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...\r\r\nConnected to 10.220.64.67.\r\r\nEscape character is '^]'.\r\r\n\r\r\n******************************************************************\r\r\n*                                                                *\r\r\n*                  Tellabs 8609 Network Element                  *\r\r\n*                                                                *\r\r\n*     Copyright (c) 2004-2015 Tellabs. All rights reserved.      *\r\r\n*                                                                *\r\r\n******************************************************************\r\r\nEnter configuration commands, one per line. End with ^Z\r\nHENKEL_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...\r\r\nConnected to 10.220.64.67.\r\r\nEscape character is '^]'.\r\r\n\r\r\n******************************************************************\r\r\n*                                                                *\r\r\n*                  Tellabs 8609 Network Element                  *\r\r\n*                                                                *\r\r\n*     Copyright (c) 2004-2015 Tellabs. All rights reserved.      *\r\r\n*                                                                *\r\r\n******************************************************************\r\r\nEnter configuration commands, one per line. End with ^Z\r\nHENKEL_CAPITAL_2-EQU>"
send: sending "enable\r" to { exp6 }

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

expect: does "\r                     \u0008\u0008\u0008\u0008\u0008\u0008\u0008\u0008\u0008\u0008\u0008\u0008\u0008\u0008\u0008\u0008\u0008\u0008\u0008\u0008\u0008HENKEL_CAPITAL_2-EQU>enable\r\n" (spawn_id exp6) match glob pattern "#"? no
HENKEL_CAPITAL_2-EQU#
expect: does "\r                     \u0008\u0008\u0008\u0008\u0008\u0008\u0008\u0008\u0008\u0008\u0008\u0008\u0008\u0008\u0008\u0008\u0008\u0008\u0008\u0008\u0008HENKEL_CAPITAL_2-EQU>enable\r\nHENKEL_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                     \u0008\u0008\u0008\u0008\u0008\u0008\u0008\u0008\u0008\u0008\u0008\u0008\u0008\u0008\u0008\u0008\u0008\u0008\u0008\u0008\u0008HENKEL_CAPITAL_2-EQU>enable\r\nHENKEL_CAPITAL_2-EQU#"
send: sending "terminal length 200\r" to { exp6 }

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

expect: does "terminal length 200\r\n" (spawn_id exp6) match glob pattern "#"? no
HENKEL_CAPITAL_2-EQU#
expect: does "terminal length 200\r\nHENKEL_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 200\r\nHENKEL_CAPITAL_2-EQU#"
send: sending "terminal more off\r" to { exp6 }

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

expect: does "terminal more off\r\n" (spawn_id exp6) match glob pattern "#"? no
HENKEL_CAPITAL_2-EQU#
expect: does "terminal more off\r\nHENKEL_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 off\r\nHENKEL_CAPITAL_2-EQU#"
send: sending "show hw-inventory details\r" to { exp6 }

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

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

Как вы думаете, это может быть проблемой с сам сценарий ожидаемого или может быть что-то еще, связанное с устройством te lnet?

Если вы готовы сделать это, мы можем провести сеанс screen, и мы можем работать вместе над этим, на этом Я чувствую отчаяние по поводу этой странной проблемы, не зная, как продолжать двигаться вперед.

Это полный ожидаемый результат:

$ 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.

В предыдущем выводе я вводил команды вручную и он работал правильно, единственная разница в том, что я не использовал терминал больше от и длина терминала 200 команды.

$ 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.

Когда я вижу --Более - string Я просто набираю пробел, чтобы получить больше выходных данных, пока не появится последнее приглашение HENKEL_CAPITAL_2-EQU # , затем я просто наберу exit команда.

Ответы [ 2 ]

0 голосов
/ 19 февраля 2020

Проблема здесь:

send "show hw-inventory details\r"
expect $prompt
send "exit\r"

Вы set prompt "#", что очень опасно. Выход show hw-inventory details имеет символ # (см. Строку part# 82.86S-8609-R6 rev C), поэтому expect $prompt будет успешным, а затем send "exit\r" и соединение будет закрыто.

Решение : Используйте более точную строку для приглашения, например:

# '[' needs to be backslash escaped or it'll trigger Tcl's command substitution
set prompt "HENKEL_CAPITAL_2-EQU\[>#]"
0 голосов
/ 15 февраля 2020

Похоже, ваша основная проблема заключается в том, что вы чередуете код (особенно эти sleep 1 s!) На разных уровнях, в результате чего получается скрипт, который на самом деле является чистым гиббери sh. То, что код не дает сбоев, является чистой случайностью.

Переписывает раздел с проблемами, пытаясь угадать, что вам нужно ...

# Handle login
expect {
    "user name:" {
        send "$user\r"
        exp_continue; # keep waiting
    }
    "password:" {
        send "$password\r"
        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 "enable\r"
expect $prompt
send "terminal length 200\r"
expect $prompt
send "terminal more off\r"
foreach cmd $commands {
    expect $prompt
    send "$cmd\r"
}
expect $prompt
send "exit\r"
expect eof

Эта техника однажды становится более ценной вы добавляете обработку ошибок, а не доверяете всему, чтобы работать, так как одна из главных сил ожидания - способность ожидать нескольких вещей одновременно. Обычно это вам не нужно, но это суперценно когда вы это делаете!

Обычно вам не нужно добавлять вызовы sleep, а не когда вы просто отправляете команду в ожидании ответа.

...