控制远程服务器的工具anyhost

anyhost是一款轻量级的远程批量操作工具,适用于需要同时控制多个远程服务器但不想使用如puppet或salt等重量级工具的场景。支持上传下载文件及批量执行命令等功能,基于Python2.6和paramiko实现。

说明

如果想同时控制多个远程服务器,又不想安装重量级的puppet,salt等运维级别的工具,可以使用此工具,需要的环境是python2.6和paramiko包。

代码位置:https://github.com/zhiyuan2007/anyhost

依赖

python 2.6 or higher
paramkio (yum install python-dev && easy_install paramiko)

用法

Usage: anhost [options]

Options:
  -h, --help            show this help message and exit
  -H HOST, --host=HOST  remote host, domain or ip is ok, can be have many -H
                        option (required unless given -f option)
  -p PASSWD, --passwd=PASSWD
                        password (required)
  -u USER, --user=USER  username (required)
  -m CMD, --cmd=CMD     list of commands will be run in remote host, can be
                        have many -m option (required)
  -s SRC, --src=SRC     source file, absolute path
  -t TRANSFER, --transfer=TRANSFER
                        transfer mode, upload or download
  -d DEST, --dest=DEST  destination filename, absolute path
  -S, --sudo            whether run cmd as root
  -T, --thread          multi-thread mode
  -f HOSTFILE, --hostfile=HOSTFILE
                        host file, used when there is many host need run
                        command
  -w WRITEFILE, --write=WRITEFILE
                        store result of command executed, valid if using -T
                        option
  -i TIMEOUT, --timeout=TIMEOUT
                        timeout of each thread if using -T option

例子

1. upload file dns_node.conf 
./anyhost -H w-f01.tool.zzct.test.net -s /home/liuguirong/wire_selfcdn/dns_node.conf -d /home/liuguirong/dns_node.conf -t upload -u xxxxxx -p xxxxxxx
2. execute command
./anyhost -H w-f01.tool.zzct.test.net -u xxxxxx -p xxxxxxx -m "df -m"
3. execute many commands once
./anyhost -H w-f01.tool.zzct.test.net -u xxxxxx -p xxxxxxx -m "df -m" -m "ifconfig" -m "ls -l"
4. execute many commands once as sudo user
./anyhost -H w-f01.tool.zzct.test.net -u xxxxxx -p xxxxxxx -m "df -m" -m "ifconfig" -m "ls -l" -S
5. execute commands on many hosts on sequence
./anyhost -f node.conf -u xxxxxx -p xxxxxxx -m "df -m"
    node.conf content is:
    hostname1
    hostname2 
6. execute commands on many hosts at same time
./anyhost -f node.conf -u xxxxxx -p xxxxxxx -m "df -m" -T
    node.conf content is:
    hostname1
    hostname2 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值