def exec_remote_list_of_cmds(hostname, commands, username='root', port=22, sudo=False):
client = paramiko.SSHClient()
client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
client.connect(hostname, port=port, username=username)
returned_array = []
for command in commands:
log.debug('command to launch in ssh in {}: {}'.format(hostname, command))
stdin, stdout, stderr = client.exec_command(command)
out = stdout.read().decode('utf-8')
err = stderr.read().decode('utf-8')
returned_array.append({'out': out, 'err': err})
log.debug('commnad launched / out: {} / error: {}'.format(out, err))
client.close()
return returned_array
评论列表
文章目录