Execute commands with paged/large outputs using asyncssh
See original GitHub issueHello Ronf, Greetings!
I have to access various vendor routers, execute some commands and process the output. Workflow is something like this - ssh to multiple devices in parallel in each device, run commands sequentially process the output of each command after execution disconnect the ssh connection
Problem is, when the output is large and paginated, I am unable to get the full output.
I went through https://github.com/ronf/asyncssh/issues/241. But couldn’t quiet figure it out.
I tried the suggestions and samples from the other discussions. I am stuck at a point. My code works fine when the output of the command is limited to a page. When the output is large and paginated, I am unable to get the complete output from the device. Can you please advise
Code snippet - ` import asyncio import sys import time import asyncssh
async def run_client(host, cmd):
k_algs = ['ecdh-sha2-nistp521', 'ecdh-sha2-nistp384', 'ecdh-sha2-nistp256', 'diffie-hellman-group14-sha1',
'diffie-hellman-group-exchange-sha1', 'diffie-hellman-group1-sha1']
e_algs = ['aes256-cbc', 'aes128-cbc', '3des-cbc', 'aes128-ctr', 'aes192-ctr', 'aes256-ctr',
'aes128-gcm@openssh.com', 'aes256-gcm@openssh.com']
m_algs = ['hmac-sha1']
print('in run_client')
async with asyncssh.connect(host, username=uname, password=pwd, port=22,
known_hosts=None, kex_algs=k_algs, encryption_algs=e_algs, mac_algs=m_algs,
compression_algs=None, ) as conn:
async with conn.create_process(cmd) as process:
print('after conn')
print("**************************%s******************************" % cmd)
process.stdin.write(f'{cmd}\r\n')
process.stdin.write_eof()
line = await process.stdout.read()
print(str(line))
async def run_multiple_clients():
host = host_ip
cmd = 'display bgp peer'
#cmd = 'display ospf interface all'
await run_client(host, cmd)
start = time.time()
asyncio.get_event_loop().run_until_complete(run_multiple_clients())
end = time.time()
print(f'Time taken : {end - start}')
`
With the above code, display bgp peer works fine since its a 2 line output. display ospf interface all returns output only until — More —
Log - ` Backup Designated Router: 0.0.0.0 Timers: Hello 10 , Dead 40 , Poll 120 , Retransmit 5 , Transmit Delay 1 ---- More ---- Time taken : 1.447819709777832
` Thanks in advance
Issue Analytics
- State:
- Created 2 years ago
- Comments:16 (7 by maintainers)
No - keep the code above basically the same, but don’t reuse “conn”. Open a new connection for each call to
create_process()
, and then send the paging disable, command, and exit on the process just like you’re doing here.Closing this issue. As mentioned, paging issue resolved with disable paging commands.