15_Linux服务器编写shell脚本

在项目上线之后,采用Jenkins自动化集成工具帮助我们自动化部署项目,往往需要在服务器编写Shell脚本来自动更新项目。
以下为我的一个脚本示例:

#!/bin/sh
cp_original="/home/app/jars/jenkins_update/store/jack.war"
cp_destination="/home/app/mj-store-test/webapps/"
project_path="/home/app/mj-store-test/"
log_path="/home/app/jars/jenkins_update/scripts/update_jack_log.txt"
cp_revert="/home/app/jars/jenkins_update/store/jack_revert.war"

cd ${project_path}
echo "$(date +%F%n%T)" > ${log_path}
echo "cd ${project_path}" >> ${log_path}
bin/shutdown.sh
echo "bin/shutdown.sh" >> ${log_path}
ps -ef | grep tomcat-mjstore | grep -v grep | cut -c 9-15 | xargs kill -9
echo "ps -ef | grep tomcat-mjstore | grep -v grep | cut -c 9-15 | xargs kill -9" >> ${log_path}
rm -rf webapps/mjstyle*
echo "rm -rf webapps/mjstyle*" >> ${log_path}
cp -f ${cp_original} ${cp_destination}
echo "cp -f ${cp_original} ${cp_destination}" >> ${log_path}
bin/startup.sh
echo "bin/startup.sh" >> ${log_path}
rm -f ${cp_revert}
mv ${cp_original} ${cp_revert}

Shell脚本编写完成之后,还需要给予其可执行权限:

chmod +x update.sh

你可能感兴趣的:(15_Linux服务器编写shell脚本)