最新消息:

Linux批量部署更新脚本

bash admin 4266浏览 0评论

随着IT 运维不断的发展,作为Linux服务器管理员,使用脚本自动化运维,可以减轻很多繁琐的工作,让你快乐工作,
发一个简单的自动化部署更新脚本,可以根据这个扩展,仅供参考。

1、批量远程执行命令脚本如下:
vi auto_deploy_ssh.sh:
#!/bin/sh
#Auto change Server Files
#Author wugk 2013-05-21

if [ ! -f ip.txt ];then
echo -e “33[31mPlease Create ip.txt Files,The ip.txt contents as follows: 33[0m”
cat < 192.168.149.128
192.168.149.129
EOF
exit
fi

if
[ -z “$*” ];then
echo -e “33[31mUsage: $0 Command ,Example {rm /tmp/test.txt | mkdir /tmp/20140228} 33[0m”
exit
fi
count=`cat ip.txt |wc -l`
rm -rf ip.txt.swp
i=0
while ((i< $count)) do i=`expr $i + 1` sed “${i}s/^/&${i} /g” ip.txt >>ip.txt.swp

IP=`awk -v I=”$i” ‘{if(I==$1)print $2}’ ip.txt.swp`

ssh -q -l root $IP “$*;echo -e ‘——————————-nThe $IP Exec Command : $* success !’;sleep 2”
done

2、批量文件拷贝及同步脚本如下:
vi auto_deploy_scp.sh
#!/bin/sh
#Auto change Server Files
#Author wugk 2014-02-27
#SRC=/etc/

if [ ! -f ip.txt ];then
echo -e “33[31mPlease Create ip.txt Files,The ip.txt contents as follows: 33[0m”
cat < 192.168.149.128
192.168.149.129
EOF
exit
fi

if

[ -z “$1” ];then
echo -e “33[31mUsage: $0 command ,example{Src_Files|Src_Dir Des_dir} 33[0m”
exit
fi

count=`cat ip.txt |wc -l`
rm -rf ip.txt.swp
i=0
while ((i< $count)) do i=`expr $i + 1` sed “${i}s/^/&${i} /g” ip.txt >>ip.txt.swp

IP=`awk -v I=”$i” ‘{if(I==$1)print $2}’ ip.txt.swp`

scp -r $1 root@${IP}:$2

#rsync -aP –delete $1 root@${IP}:$2

done

 

转载请注明:爱开源 » Linux批量部署更新脚本

您必须 登录 才能发表评论!