赞
踩
一个python项目自动下载打包传输的shell脚本
- #!/bin/bash
-
- project_name=`echo ${1}|sed 's/\///g'`
-
- test_machine="test1.ssss.ss.com"
- restart_script="restart.sh"
-
- if [[ -z "$project_name" ]];then
- echo "usage:./deploy ProjectFolderName"
- exist 1
- fi
-
- echo "[Info] git pull in ${project_name} start"
- cd ${project_name}
- git pull
- cd ..
- echo "[Info] git pull in ${project_name} done"
-
- project_tar="${project_name}.tar"
- echo "[Info] compress tar file ${project_tar} start!"
- tar zvcf ${project_tar} --exclude=.git --exclude=__pycache__ --exclude=test --exclude=.idea --exclude=.gitignor ${project_name} 1>/dev/null
- echo "[Info] compress tar file ${project_tar} done!"
-
- echo "[Info] star to ssh ${project_tar} to ${test_machine}"
- scp_cmd="scp ${project_tar} ${test_machine}:/home/ambition"
- echo "scp command:${scp_cmd}"
- ${scp_cmd}
- sleep 3s
-
-
- echo "[Info] start to ssh test_machine"
- ssh ${test_machine} << sdsds
- sleep 2s
- cd ~
- echo "[Info] decompress tar file ${project_tar} start!"
- tar -xvf ${project_tar} 1>/dev/null
- echo "[Info] decompress tar file done!"
- echo "[Info] start to copy test machine config file"
- scp -r ark_temp_yxx/* ${project_name}/
- echo "[Info] copy test machine config file done"
- cd ${project_name}
- echo "current pwd `pwd`"
- ./${restart_script}
- echo "[Info] run script on test machine Done!"
- sdsds
解析1;sed 去掉项目前的/
project_name=`echo ${1}|sed 's/\///g'`
具体作用是去掉项目前的/
[xx@server1] ~$ echo /my_project|sed 's/\///g'
my_project
解析二:
注意命令执行的几种方式:
方式1:直接命令放一行
${scp_cmd}
方式二:单反号``中的会执行命令
echo "current pwd `pwd`"
方式三:命令与变量拼接方式
cd ${project_name}
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。