Try using python and pexpect module to collect data on the switch, how can I sort the result of 2 commands into one?

import pexpect
import sys
res1=sys.stdout.buffer
command = ["show mac-address-table ", "show interface ethernet status"]
t="terminal length 0"
user = "user"
password = "password"
ip =sys.argv[1]
rsa_key=('(yes/no)?')
en=('password:')
ssh=pexpect.spawn('ssh {}@{}'.format(user, ip))
i=ssh.expect([rsa_key, en,""])
if i==0:
ssh.sendline('yes')
ssh.expect(en)
ssh.sendline(password)
elif i==1:
ssh.sendline(password)
else:
ssh.sendline(password)
ssh.logfile=res1
ssh.expect('#')
ssh.sendline(t)
ssh.expect('#')
ssh.sendline(command[0])
ssh.expect('#')
ssh.sendline(command[1])
ssh.expect('#')
ssh.sendline('exit')
print(res1)

Result 1 team:
vlan mac address Ports Creator
1 AA-AA-AA-AA-AA-AA Hardware Ethernet 1/0/1
1 11-11-11-11-11-11 Hardware Ethernet 1/0/18
1 CC-CC-CC-CC-CC-CC Hardware Ethernet 1/0/3
1 BB-BB-BB-BB-BB-BB Hardware Ethernet 1/0/4

The result of the 2nd command:
Interface Link/Protocol Speed Duplex Vlan
1/0/1 UP/UP a-1G a-FULL trunk
1/0/2 DOWN/DOWN auto auto 1
1/0/3 DOWN/DOWN auto auto 1
1/0/4 UP/UP a-100M a-FULL 1
1/0/5 UP/UP a-100M a-FULL 1
1/0/6 DOWN/DOWN auto auto 1
1/0/7 DOWN/DOWN auto auto 1
1/0/8 DOWN/DOWN auto auto 1

The end result should be something like this:

[Port: 1 Link status: UP]
AA:AA:AA:AA:AA:AA

[Port: 2 Link status: DOWN]

[Port: 3 Link status: UP]
SS:SS:SS:SS:SS:SS

[Port: 4, Link status: UP]
BB:BB:BB:BB:BB:BB
...

[Port: 18, Link status: UP]
00:00:00:00:00:00
11:11:11:11:11:11
22:22:22:22:22:22
33:33:33:33:33:33
April 7th 20 at 15:53
0 answer

Find more questions by tags Python