简单的linux服务器部署shell脚本

最近需要经常部署工程到prod服务器,
需要把jenkins build出来的war包手动scp到目标服务器
为了简化每次的操作,写了如下脚本:

jenkins build target服务器脚本

#!/bin/sh

if [ -z "$1" ]; then
    echo 'usage: scp.sh app_name'
    exit 1
fi

if [ "$1" = "bbd" ]; then
        scp /usr/local/app/dist/bbd-admin/target/bbd-admin.war yuhao@10.168.116.238:~
elif ["$1" = "oms" ]; then
        scp /usr/local/app/dist/oms-web/target/JunFangWeb.war yuhao@10.117.30.143:~
else
        echo "unknown application name $1"
        exit 1
fi




目标服务器部署脚本

#!/bin/sh

if [ -z "$1" ]; then
    echo 'usage: scp.sh app_name'
    exit 1
fi

if [ "$1" = "bbd" ]; then
        /usr/local/tomcat/tomcat-instance9/shutdown-instance9.sh
        mkdir tmp
        ls ROOT.war.bak* | tail -2 |  xargs -I {} mv {} tmp/
        rm /home/yuhao/ROOT.war*
        ls ./tmp/ | xargs -I {} cp ./tmp/{} ./
        rm -r tmp
        cp /usr/local/tomcat/tomcat-instance9/webapps/ROOT.war /usr/local/tomcat/tomcat-instance9/ROOT.war.bak.$(date +%m%d)
        cp /home/yuhao/bbd-admin.war /usr/local/tomcat/tomcat-instance9/webapps/ROOT.war
        /usr/local/tomcat/tomcat-instance9/startup-instance9.sh
elif ["$1" = "oms" ]; then
        scp /usr/local/app/dist/oms-web/target/JunFangWeb.war yuhao@10.117.30.143:~
else
        echo "unknown application name $1"
        exit 1
fi

posted @ 2017-08-11 14:53  乱笙歌  阅读(723)  评论(0编辑  收藏  举报