shell 更新所有git目录

有时候,很久不接触的项目,突然要更新使用,而又懒的一个目录一个目录的去做更新处理,顾整理了一个shell脚本来做处理,同时也做为之前写的一篇文章的更新吧!链接 :http://genggeng.iteye.com/blog/1128679

 

代码如下:

 

Shell代码   收藏代码
  1. #!/bin/bash -x   
  2.   
  3. PROJECTS_DIR=/home/gavingeng/projects/email  
  4.   
  5. function update_all()  
  6. {  
  7.     for d in `ls`  
  8.     do    
  9.     #  echo $d;    
  10.         cd $PROJECTS_DIR/$d  
  11.         echo "update project:current_dir: $PWD"  
  12.         `git pull` >>/home/gavingeng/tmp/test.log 2>&1 &   
  13.         sleep 5  
  14.         echo "update success  ^_^"  
  15.     done  
  16. }  
  17.   
  18. function update()  
  19. {  
  20.     echo "hello ,u can update"    
  21.     `git pull` >>/tmp/test.log 2>&1 &  
  22.     echo "update success  ^_^"  
  23. }  
  24.   
  25. cd $PROJECTS_DIR  
  26.   
  27. if [ -z  "$1"  ];then  
  28.     update_all  
  29. elif [ -d  "$PROJECTS_DIR/$1" ];then  
  30.     cd $PROJECTS_DIR/$1  
  31.     echo $PWD  
  32.     update  
  33. else  
  34.     echo "not exist \"$PROJECTS_DIR/$1\""  
  35.     exit 0;  
  36. fi  

 

在做git更新时,若没有更新,就会出现"Already date to date",这里将它重定向到日志中做处理

 

今天又对脚本进行了更新、处理,如下:

 

Shell代码   收藏代码
  1. #!/bin/bash -x   
  2.   
  3. PROJECTS_DIR=/home/gavingeng/projects/email  
  4.   
  5. ##排除以下情况:  
  6. ##1.非目录  
  7. ##2.非git目录  
  8.   
  9. function is_git_dir(){  
  10.     param=`find $PWD -name ".git"`  
  11.     if [ -z "$param" ];then  
  12.     return 1 #1为假  
  13.     else  
  14.     return 0 #0为真  
  15.     fi      
  16. }  
  17.   
  18. function update_all()  
  19. {  
  20.     for d in `ls`  
  21.     do  
  22.         if [ -d "$PROJECTS_DIR/$d" ];then  
  23.         #  echo $d;    
  24.             cd $PROJECTS_DIR/$d  
  25.   
  26.         if is_git_dir $PWD;then  
  27.             echo "update project:current_dir: $PWD"  
  28.             `git pull` >>/home/gavingeng/tmp/test.log 2>&1 &   
  29.             sleep 5  
  30.             echo "update success  ^_^"  
  31.         else  
  32.         echo "$PWD is not a git dir!"  
  33.         fi  
  34.     else  
  35.         echo "$d is not a dirctory"  
  36.     fi  
  37.     done  
  38. }  
  39.   
  40. function update()  
  41. {  
  42.     echo "hello ,u can update"    
  43.     `git pull` >>/tmp/test.log 2>&1 &  
  44.     echo "update success  ^_^"  
  45. }  
  46.   
  47.   
  48. cd $PROJECTS_DIR  
  49.   
  50. if [ -z  "$1"  ];then  
  51.     update_all  
  52. elif [ -d  "$PROJECTS_DIR/$1" ];then  
  53.     cd $PROJECTS_DIR/$1  
  54.     echo $PWD  
  55.     if is_git_dir $PWD;then  
  56.       update  
  57.     else  
  58.     echo "$PWD is not a git dir!"  
  59.     fi  
  60. else  
  61.     echo "not exist \"$PROJECTS_DIR/$1\""  
  62.     exit 0;  
  63. fi  
 

改完后,发现if/else逻辑更多了,该想想如何去改了......

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值