When I execute a script, I obtain the following text into terminal:
GN status:
MAC addr: 10:98:C3:73:64:CD
Lastest Update Time: 2021-11-18 10:26:18(GMT+0)
--- Media Layer---
TX Packet:
Total: 68360
Success: 68360
Failure: 0
RX Packet:
Total: 751063
Success: 751063
Dropped: 0
CRC Error: 313
All I want to do is to obtain the value 751063:
RX Packet:
Total: 751063
How can I show only this number into the terminal and erase all the other words?
Have you tried anything on your own?
this will work:
your_command|grep 'RX Packet:' -A1|grep Total|head -1|awk '{print $2}'
Related
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 "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
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...\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"
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.
The problem is in here:
send "show hw-inventory details\r"
expect $prompt
send "exit\r"
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 "exit\r" 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\[>#]"
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 "$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
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.
I would like to break a long string by the word count and then continue display and break once every certain number of words reached.
For example.
I have a string :
value="Aug 04 03:49:00.082205 ALERT IPX-NG dropped -- total: 4693845, count: 39254, rate: 1.88% ; OUTPUT QUEUE frampedd: active=1, delivered=73265000210 Aug 04 09:43:00.795817 ALERT IPX-NG dropped -- total: 4765909, count: 72064, rate: 1.91% ; OUTPUT QUEUE frampedd: active=0, delivered=74220627600"
my expected output is :
Aug 04 03:49:00.082205 ALERT IPX-NG dropped -- total: 4693845, count: 39254, rate: 1.88% ; OUTPUT QUEUE frampedd: active=1, delivered=73265000210
Aug 04 09:43:00.795817 ALERT IPX-NG dropped -- total: 4765909, count: 72064, rate: 1.91% ; OUTPUT QUEUE frampedd: active=0, delivered=74220627600"
I couldn't use by character count as the number will be vary. So the best choice is to use word count.
EDIT:
Hi Guys,..i tried using the sed command and it seems to work!
sed 's/([^[:space:]]{1,}[[:space:]]{1,}){19}/&\n/'
thanks those who helps..you can give me better suggestions if there is :D.. would hope for pure bash command as i'm unable to install any other extension on the server.
If all the string count doesn't change, you can use xargs
$ value="Aug 04 03:49:00.082205 ALERT IPX-NG dropped -- total: 4693845, count: 39254, rate: 1.88% ; OUTPUT QUEUE frampedd: active=1, delivered=73265000210 Aug 04 09:43:00.795817 ALERT IPX-NG dropped -- total: 4765909, count: 72064, rate: 1.91% ; OUTPUT QUEUE frampedd: active=0, delivered=74220627600"
$ xargs -n 19 <<< "$value"
Aug 04 03:49:00.082205 ALERT IPX-NG dropped -- total: 4693845, count: 39254, rate: 1.88% ; OUTPUT QUEUE frampedd: active=1, delivered=73265000210
Aug 04 09:43:00.795817 ALERT IPX-NG dropped -- total: 4765909, count: 72064, rate: 1.91% ; OUTPUT QUEUE frampedd: active=0, delivered=74220627600
The xargs man page says this about the flag -n
-n max-args, --max-args=max-args
Use at most max-args arguments per command line. Fewer than
max-args arguments will be used if the size (see the -s
option) is exceeded, unless the -x option is given, in which
case xargs will exit.
In AWK:
awk '{{gsub(/^value="|"$/,""); for(i=1;i<=NF;i++) printf "%s%s",$i,(i%19?" ":"\n")}' file
or if your string does not in fact start with value=", you can loose the gsub:
awk '{for(i=1;i<=NF;i++) printf "%s%s",$i,(i%19?" ":"\n")}' file
I execute a curl [url] command in a Linux shell script. I want to get this command's exit code and its output at the same time without using a temporary file.
Is there any method to do that?
I'm assuming the problem is that you have an intermediary command that's supplanting the exit code of the last command.
To get around this, just store the exit code and stdout in variables:
OUTPUT=$(curl example.org)
EXIT_CODE=$?
then you can simply output these either in the same line:
echo "$EXIT_CODE: $OUTPUT"
or call them separately as needed.
(I don't have enough reputation points to comment on user559633's answer.)
Apparently this won't work if you send STDOUT to a local variable:
test.sh:
#!/bin/bash
function test1 () {
OUTPUT=$( ping -c 1 -W 1 blah.org )
EXIT_CODE=$?
echo "$EXIT_CODE: $OUTPUT"
}
function test2 () {
local OUTPUT=$( ping -c 1 -W 1 blah.org )
EXIT_CODE=$?
echo "$EXIT_CODE: $OUTPUT"
}
test1
test2
Output:
# ./test.sh
1: PING blah.org (205.150.150.140) 56(84) bytes of data.
--- blah.org ping statistics ---
1 packets transmitted, 0 received, 100% packet loss, time 0ms
0: PING blah.org (205.150.150.140) 56(84) bytes of data.
--- blah.org ping statistics ---
1 packets transmitted, 0 received, 100% packet loss, time 0ms
Note the exitcode from test1 is 1, but for test2, it's 0.
EDIT: It seems that separating the local declaration from the assignment takes care of this:
#!/bin/bash
function test1 () {
OUTPUT=$( ping -c 1 -W 1 blah.org )
EXIT_CODE=$?
echo "$EXIT_CODE: $OUTPUT"
}
function test2 () {
local OUTPUT
OUTPUT=$( ping -c 1 -W 1 blah.org )
EXIT_CODE=$?
echo "$EXIT_CODE: $OUTPUT"
}
test1
test2
Output:
1: PING blah.org (205.150.150.140) 56(84) bytes of data.
--- blah.org ping statistics ---
1 packets transmitted, 0 received, 100% packet loss, time 0ms
1: PING blah.org (205.150.150.140) 56(84) bytes of data.
--- blah.org ping statistics ---
1 packets transmitted, 0 received, 100% packet loss, time 0ms
There's no standard way to get the exit status of a command within a pipe.
However, if you're using (or able to use) Bash as your shell, the PIPESTATUS built-in array variable holds the results of the most recent pipeline executed. (Note that a single command counts as a pipeline here).
Example:
true | false | false | false; echo "${PIPESTATUS[0]}" "${PIPESTATUS[1]}"
Output:
0 1
I would like to ask you for help: Does somebody know how to detect Cisco Discovery Protocol via tcpdump?
Currently I'm using following command, but I'm not sure by this:
tcpdump -i eth0 -nn "ether[20:2]==0x2000"
Some hints are appreciated. Thank you ...
Charkh
I normally use this filters
tcpdump -nvi bce0 -s 1500 ether dst 01:00:0c:cc:cc:cc
replace bce0 with your network interface.
This will output the hole CDP information, received from ether the switch or the host itself (if you have a cdpd running on the host)
This will output Switch-Name, Port, Switch Type, Software, VLAN and so on...
the output will look similar to this:
$tcpdump -nvi bce0 -s 1500 ether dst 01:00:0c:cc:cc:cc
tcpdump: WARNING: bce0: no IPv4 address assigned
tcpdump: listening on bce0, link-type EN10MB (Ethernet), capture size 1500 bytes
11:43:24.327197 DTPv1, length 39
Domain TLV (0x0001) TLV, length 18, domain-internal
Status TLV (0x0002) TLV, length 5, 0x81
DTP type TLV (0x0003) TLV, length 5, 0xa5
Neighbor TLV (0x0004) TLV, length 10, 6c:50:4d:06:64:01
11:43:44.820865 CDPv2, ttl: 180s, checksum: 692 (unverified), length 477
Device-ID (0x01), length: 40 bytes: 'my-switch.mydomain.net'
Version String (0x05), length: 247 bytes:
Cisco IOS Software, CBS30X0 Software (CBS30X0-IPBASEK9-M), Version 12.2(58)SE1, RELEASE SOFTWARE (fc1)
Technical Support: http://www.cisco.com/techsupport
Copyright (c) 1986-2011 by Cisco Systems, Inc.
Compiled Thu 05-May-11 03:57 by prod_rel_team
Platform (0x06), length: 20 bytes: 'cisco WS-CBS3020-HPQ'
Address (0x02), length: 13 bytes: IPv4 (1) 1.2.3.4
Port-ID (0x03), length: 18 bytes: 'GigabitEthernet0/1'
Capability (0x04), length: 4 bytes: (0x00000028): L2 Switch, IGMP snooping
Protocol-Hello option (0x08), length: 32 bytes:
VTP Management Domain (0x09), length: 13 bytes: 'doman-internal'
Native VLAN ID (0x0a), length: 2 bytes: 358
Duplex (0x0b), length: 1 byte: full
AVVID trust bitmap (0x12), length: 1 byte: 0x00
AVVID untrusted ports CoS (0x13), length: 1 byte: 0x00
Management Addresses (0x16), length: 13 bytes: IPv4 (1) [IP]
unknown field type (0x1a), length: 12 bytes:
0x0000: 0000 0001 0000 0000 ffff ffff
I use the following command:
tcpdump -nn -v -xx -i eth? -s 1500 -c 1 'ether dst 01:00:0c:cc:cc:cc and (ether[24:2] = 0x2000 or ether[20:2] = 0x2000)'
Where eth? is your ethernet adapter.
It can be used with IBM SEA over trunked connections or over standard copper connections.
When i am doing pactl list i get lot of information. Out of those information, i am trying to only get the part start with Sink #0 till end of that section.
1) Information's
Sink #0
State: SUSPENDED
Name: auto_null
Description: Dummy Output
Driver: module-null-sink.c
Sample Specification: s16le 2ch 44100Hz
Channel Map: front-left,front-right
Owner Module: 14
Mute: no
Volume: 0: 0% 1: 0%
0: -inf dB 1: -inf dB
balance 0.00
Base Volume: 100%
0.00 dB
Monitor Source: auto_null.monitor
Latency: 0 usec, configured 0 usec
Flags: DECIBEL_VOLUME LATENCY
Properties:
device.description = "Dummy Output"
device.class = "abstract"
device.icon_name = "audio-card"
Source #0
State: SUSPENDED
Name: auto_null.monitor
Description: Monitor of Dummy Output
Driver: module-null-sink.c
Sample Specification: s16le 2ch 44100Hz
Channel Map: front-left,front-right
Owner Module: 14
Mute: no
Volume: 0: 80% 1: 80%
0: -5.81 dB 1: -5.81 dB
balance 0.00
Base Volume: 100%
0.00 dB
Monitor of Sink: auto_null
Latency: 0 usec, configured 0 usec
Flags: DECIBEL_VOLUME LATENCY
Properties:
device.description = "Monitor of Dummy Output"
device.class = "monitor"
device.icon_name = "audio-input-microphone"
2) I am trying, such as:
#!/bin/bash
command=$(pactl list);
# just get Sink #0 section not one line
Part1=$(grep "Sink #0" $command);
for i in $Part1
do
# show only Sink #0 lines
echo $i;
done
3) It output very strange
grep: dB: No such file or directory
How can i get that section using my BASH script, is there any other best way to work on such filtering?
Follow up: So i was also trying to keep it simple. such as:
pactl list | grep Volume | head -n1 | cut -d' ' -f2- | tr -d ' '
|________| |________| |______| |_____________| |_________|
| | | | |
command target get show 1 row cut empty Dont know..
to list
You can use several features of the sed editor to achieve your goal.
sed -n '/^Sink/,/^$/p' pactl_Output.txt
-n says "don't perform the standard option of printing each line of output
/^Sink/,/^$/ is a range regular expr, that says find a line that begins with Sink, then keep looking at lines until you find an empty line (/^$/).
the final char, p says Print what you have matched.
If there are spaces or tabs on the empty line, use " ...,/^$[${spaceChar}${tabChar}]*\$/p". Note the change from single quoting to dbl-quoting which will allow the variables ${spaceChar} and ${tabChar} to be expanded to their real values. You may need to escape the closing '$'. YOu'll need to define spaceChar and tabChar before you use them, like spaceChar=" " . No way here on S.O. for you to see the tabChar, but not all sed's support the \t version. It's your choice to go with pressing tab key or use \t. I would go with tab key as it is more portable.
While it is probably possible to accomplish your goal with bash, sed was designed for this sort of problem.
I hope this helps.
Try:
Part1=`echo $command | grep "Sink #0"`
instead of
Part1=$(grep "Sink #0" $command);