代码上线的shell脚本

原文链接: https://yq.aliyun.com/articles/673544

本脚本来自有学习阿铭的博文学习:
工作中,生产环境中一个业务在跑在多台机器上,为的是负载均衡,高可用。如何让这些代码保持一致呢?

提示:本文中的S全部都$符,不要问为什么,马云爸爸的社区就这样。

#!/bin/bash
#用途:代码上线的的shell脚本。
#作者:Caron maktini
#日期:2018年11月27日
#版本:v0.1

#提醒用户,是否更新了要上线的代码列表文件 
read -p "你是否已经更新了文件列表./file.list?确认请输入Y,或者按其他任意键退出脚本。" a

#如果直接按回车,也会退出脚本 
if [ -z "$a" ]
then 
      exit 1
fi

if [ Sa == "y" -o $a == "Y" ]
then 
    echo "脚本将在2秒后,继续执行。" 
     #每秒输出一个。共输出两个 

    for i in 1 2 
    do 
        echo  -n "."
        sleep 1 
    done 
    echo 
else 
    exit 1 
fi 

#判断有无./rsync.exp文件 
[ -f ./rsync.exp ] && rm -f ./rsync.exp 

#定义rsync. exp 
cat > ./rsync.exp << EOF 
#!/usr/bin/expect 
  set passwd "密码"   
  set host [lindex \$argv 0] 
  set file [lindex \$argv 1]

spawn rsync -avR  --files-from=\$file   /   user#\S host:/ 
expect  {
    "yes/no"  {send "yes\r"} 
    "password:"  {send  \$passwd\r} 
}

expect eof 
EOF 

chmod a+x ./rsync.exp 

#定义检测文件是否存在的函数 
if_file_exist()
{
     if  [ ! -f $1 ]
    then 
         echo "文件$1不存在,请检查。"
         exit 1
 }
 
#ip.list为所有WEB机器的ip列表 
#file.list为要同步的文件列表 

for ip in `cat ./ip.Iis` 
do 
    ./rsync.exp $ip ./file.Iist 
done 

#善后处理 
rm-f  rsync.exp 


#创建user01用户,并且保证user01用户对WED用户有写权限。




你可能感兴趣的:(代码上线的shell脚本)