栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

Boto在EC2实例上执行Shell命令

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

Boto在EC2实例上执行Shell命令

boto.manage.cmdshell模块可用于执行此操作。要使用它,您必须安装paramiko软件包。一个简单的用法示例:

import boto.ec2from boto.manage.cmdshell import sshclient_from_instance# Connect to your region of choiceconn = boto.ec2.connect_to_region('us-west-2')# Find the instance object related to my instanceIdinstance = conn.get_all_instances(['i-12345678'])[0].instances[0]# Create an SSH client for our instance#    key_path is the path to the SSH private key associated with instance#    user_name is the user to login as on the instance (e.g. ubuntu, ec2-user, etc.)ssh_client = sshclient_from_instance(instance,    '<path to SSH keyfile>',    user_name='ec2-user')# Run the command. Returns a tuple consisting of:#    The integer status of the command#    A string containing the output of the command#    A string containing the stderr output of the commandstatus, stdout, stderr = ssh_client.run('ls -al')

这是从记忆中键入的,但我认为是正确的。

您还可以签出Fabric(http://docs.fabfile.org/),它具有相似的功能,但也具有更为复杂的功能。



转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/639544.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号