部署应用的小脚本

 1 #!/bin/bash
 2 # Author        : standby
 3 # Date          : 2017-05-12
 4 # Description   : Deploy something.
 5 
 6 . /etc/init.d/functions
 7 
 8 # Usage...
 9 function Usage()
10 {
11     echo -e "Usage: /bin/sh $0 arg1 arg2\n \
12                   - arg1 like this : data1 | data2 ...\n \
13                   - arg2 like this : tag"
14     exit 2
15 }
16 # The core deploy code block here...
17 function deploy()
18 {
19     # Prepare something...
20     # ...
21     # Deploy some crontab and script...
22     # ...
23 }
24 # Verificate the arguments.
25 function verificate()
26 {
27     result=0
28     available=`df -m |grep $1$ |awk '{print $4}'`
29     [[ $available -lt 1000000 ]] && result=1
30     [[ $2 == x* ]] || result=2
31     #[ $2 == x* ] || result=2
32     echo $result
33 }
34 # Start something processes.
35 function start_work()
36 {
37     if [ $1 -eq 1 ]
38     then
39         echo -e "\n"
40         action "Deploy something successful." /bin/true
41         echo -e "\nBegin to start something process...\n"
42         # start something cmd here ...
43         if [ $? -eq 0 ]
44         then
45             action "Start something successful." /bin/true
46         else
47             action "Start something failed." /bin/false
48         fi
49     elif [ $1 -eq 2 ]
50     then
51         action "Deploy something failed." /bin/false
52     exit -1
53     else
54         action "You are not expected to undestand this code block ->_->" /bin/true
55     fi
56 }
57 # Main code body.
58 function main()
59 {
60     [[ $1 == dat* ]] || Usage
61     result=`verificate $1 $2`
62     #echo $result
63     if [ $result -eq 0 ]
64     then
65         #echo "Hello world!"
66         deploy $1 $2
67         [ $? -eq 0 ] && start_work 1 || start_work 2
68     elif [ $result -eq 1 ]
69     then
70         echo "$1 have less than 1T space left"
71         exit 1
72     elif [ $result -eq 2 ]
73     then
74         echo "The arg2 must start with 'x', not $2"
75         exit 2
76     fi
77 }
78 # Start here...
79 if [ $# -ne 2 ]
80 then
81     Usage
82 else
83     main $1 $2
84 fi

 

转载于:https://www.cnblogs.com/standby/p/6847554.html

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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值