I am trying to execute a remote command on an ec2 instance that needs sudo.
example code snippet
conn = boto.ec2.connect_to_region(....)
instance = conn.get_only_instances(instance_ids=instance_id)[0]
ssh_client = sshclient_from_instance(instance, ssh_key_file='path.to.pem,user_name='ec2-user')
chan = ssh_client.run_pty('sudo ls /root')
Using just ssh_client.run() returns a tuple that was easy to deal with but doesn't allow sudo. run_pty is returning paramiko.channel.Channel and I can use recv() to get some output back but I am not clear how to get the entire stdout.
来源:https://stackoverflow.com/questions/27711530/correct-way-to-get-output-of-run-pty-from-a-boto-sshclient