一个脚本从git上pull 并更新到服务器

#/bin/bash

cd /src/pid01-beta/

echo "update pid01.."

git pull

if [ $? -ne 0 ]; then
        echo "update pid01(clientErrorCode.json) from git failed"
        exit 1
fi

res=`git pull|grep -c "up-to-date"`

if [ $res -eq 1 ]; then 
        echo "pid01 already latest,quit update"
        exit 1
fi


go build

if [ $? -ne 0 ]; then
        echo "go build failed"
        exit 1
fi

rm -rf /data/wesite/pid01-beta

if [ $? -ne 0 ]; then
        echo "delete old pid01 file failed"
        exit 1
fi


mv /src/pid01-beta/pid01-beta /data/website/

if [ $? -ne 0 ]; then
        echo "move new pid01 file failed"
        exit 1
fi


pidno=`ps aux|grep  pid01|grep -v "grep"|awk '{print $2}'`

kill -9 $pidno

if [ $? -ne 0 ]; then
        echo "old pid01 kill failed"
        exit 1
fi

sleep 5

pid01pid=`ps aux|grep  pid01|grep -v "grep"|awk '{print $2}'`

if [ "$pid01pid" ];then 
      echo "new version pid01 is running now"
      
fi
原文地址:https://www.cnblogs.com/weifeng1463/p/7680093.html