- 添加主机列表,hosts文件的内容:
<pre>servers=(ali-cache ali-web1 ali-web2 ali-web3 ali-web4 ali-web5 ali-web6 ali-web7 ali-web8)</pre> - 发布代码到多台服务器
<pre>
source hosts
for server in ${servers[@]}; do
echo "-------------------${server}-------------------"
scp -r $1 ${server}:$2
done
</pre> - 在多台服务器上执行相同命令
<pre> #!/usr/bin/env bash
source hosts
for server in ${servers[@]}; do
echo "-------------------${server}-------------------"
ssh $server "$1"
done</pre>