Correct way to get output of run_pty from a boto sshclient

人走茶凉 提交于 2019-12-08 03:57:48

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!