当前位置:   article > 正文

shell脚本练习:python项目自动下载打包传输的shell脚本

shell脚本练习:python项目自动下载打包传输的shell脚本

一个python项目自动下载打包传输的shell脚本

  1. #!/bin/bash
  2. project_name=`echo ${1}|sed 's/\///g'`
  3. test_machine="test1.ssss.ss.com"
  4. restart_script="restart.sh"
  5. if [[ -z "$project_name" ]];then
  6. echo "usage:./deploy ProjectFolderName"
  7. exist 1
  8. fi
  9. echo "[Info] git pull in ${project_name} start"
  10. cd ${project_name}
  11. git pull
  12. cd ..
  13. echo "[Info] git pull in ${project_name} done"
  14. project_tar="${project_name}.tar"
  15. echo "[Info] compress tar file ${project_tar} start!"
  16. tar zvcf ${project_tar} --exclude=.git --exclude=__pycache__ --exclude=test --exclude=.idea --exclude=.gitignor ${project_name} 1>/dev/null
  17. echo "[Info] compress tar file ${project_tar} done!"
  18. echo "[Info] star to ssh ${project_tar} to ${test_machine}"
  19. scp_cmd="scp ${project_tar} ${test_machine}:/home/ambition"
  20. echo "scp command:${scp_cmd}"
  21. ${scp_cmd}
  22. sleep 3s
  23. echo "[Info] start to ssh test_machine"
  24. ssh ${test_machine} << sdsds
  25. sleep 2s
  26. cd ~
  27. echo "[Info] decompress tar file ${project_tar} start!"
  28. tar -xvf ${project_tar} 1>/dev/null
  29. echo "[Info] decompress tar file done!"
  30. echo "[Info] start to copy test machine config file"
  31. scp -r ark_temp_yxx/* ${project_name}/
  32. echo "[Info] copy test machine config file done"
  33. cd ${project_name}
  34. echo "current pwd `pwd`"
  35. ./${restart_script}
  36. echo "[Info] run script on test machine Done!"
  37. 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}

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/我家小花儿/article/detail/156684
推荐阅读
相关标签
  

闽ICP备14008679号