shell脚本实现同时管理多台服务器,未使用ansible,自动手动实现
ssh不登录机器执行命令(前提得实现无密码登录)
ssh 127.0.0.1 'ifconfig' ssh 127.0.0.1 'ifconfig|grep bbb' ssh 127.0.0.1 'tail /var/log/secure'
shell while循环读取需要管理的服务器的ip列表
cat /tmp/hosts|while read line;do echo $line; done
结合上述两个实现同时管理多台服务器
- 一开始的想法,但没办法同时管理多台服务器,只能管理1台
cat /tmp/hosts|while read line;do echo $line ssh $line 'tail /var/log/secure' done
@H_502_16@ - 打到日志的一个尝试,还是不行
cat /tmp/hosts|while read line;do echo $line ssh $line 'tail /var/log/secure' >/tmp/${line}.log done
@H_502_16@ -
尝试成功,必须要放在后台&
cat /tmp/hosts|while read line;do echo $line ssh $line 'tail /var/log/secure' >/tmp/${line}.log & done
ssh无密码,scp也是无密码。
综合上述的情况,我们已经可以实现同时管理多台服务器,批量运行命令,批量上传文件,批量下载文件 。
@H_502_16@