http://www.21yunwei.com/archives/5307
记录一个shell脚本小实例,线上服务器同步代码到web节点脚本。
- #!/bin/bash
- #author:21yunwei
- c="$1";
- if [ "$c" != "1" ]; then
- echo "EXIT";
- exit;
- fi
- #定义web节点池
- webnode=(
- 21yunwei-web1
- 21yunwei-web2
- 21yunwei-web3
- 21yunwei-web4
- )
- #循环同步数据,从测试站点目录更新到正式站点目录
- for host in ${webnode[@]}
- do
- echo "rsync data to $host"
- rsync -avz -P -e ssh /wwwroot/21yunwei-prelive/* $host:/wwwroot/21yunwei/
- done
- ret=$?
- if [ $ret -eq 0 ]
- then
- echo "$1 同步完毕"
- else
- echo "$1 同步失败,请检查"
- fi
用法:./rsync_to_web.sh 1
假设脚本名字为rsync_to_web.sh