yum install -y ansible 编辑 /etc/ansible/hosts 文件 # This is the default ansible 'hosts' file.## It should live in /etc/ansible/hosts## - Comments begin with the '#' character # 用#来表示注释# - Blank lines are ignored # 空白行被忽略# - Groups of hosts are delimite
因为老板一个电话,我的国庆节就没了....,老板要我写个东西,能批量执行500台windows的命令并返回结果,虽然完成以后是非常的简单,但是因为我走了很多弯路,一开始想用powershell来写,后来又改成VBS的,最后还是用了最简单的CMD的命令的来完成,代码如下: @echo off set user=test for /f "tokens=1,2" %%i in (iplist.txt) do ( echo -------%date%--%time%----
经常要部署多台服务器上面的应用,如果一个个机器的登录太麻烦. 所有就想到编写一个脚本来部署不同的服务器 前提条件: 配置ssh免登陆 如果不会的请参加我的另外一篇文章 http://blog.csdn.net/chenpy/article/details/30281515 两个错误: Pseudo-terminal will not be allocated because stdin is not a terminal.使用ssh -t -t 可以解决 另外一个问题Agent admitted
#!/bin/bash ssh_hosts=("IP" "IP1".......) user=root remote_cmd="df -h" port=22 for ip in ${ssh_hosts[*]} do ssh -t $user@$ip $remote_cmd done 其中remote_cmd改成你想执行的命令,其中控制机和被执行命令的机器做了免秘钥登录
在shell中有很多种命令的同义词,到底先执行的是哪一个命令呢,我们可以借助type -a命令来检查. 为了测试我们就对type本身做一条alias: alias type=type 然后我们通过type -a type查看一下,结果如下: type -a type type is aliased to `type' type is a shell builtin type is /usr/bin/type 可以清楚地看到,对于命令来说首先执行的是alias,然后是shell内嵌的命令,最后才是