I am trying to create a loop for an interactive ssh command with asyncssh. This works as i need it for one host, but after first run all redirect channels are closed. See code below.
Is there any way to get around that?
----------------
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import asyncio, asyncssh, sys
async def run_client(host,cmd):
async with asyncssh.connect(host) as conn:
await conn.run(cmd, term_type='xterm-256color',
stdin=sys.stdin,
stdout=sys.stdout,
stderr=sys.stderr
)
cmd = 'bc'
hosts = 2 * [ 'localhost' ]
for host in hosts:
try:
print("--- Run on:",host)
asyncio.get_event_loop().run_until_complete(run_client(host,cmd))
except (OSError, asyncssh.Error) as exc:
sys.exit('SSH connection failed: ' + str(exc))