shell case学习编写

#!/bin/bash
ops1 () {
case $1 in
        a)
        echo "A" ;;
        b)
        echo "B" ;;
        *)
        ccc
esac
}
ccc () {
echo "
写自己想写东西
比如说
A是什么功能
B是什么功能 都可以写
"
}
ops1 $@  #   $@和$* 意思差不多,都是引用所有参数。具体详情百度



#!/bin/bash
function ops() {
    case $1 in 
    oob)
    msn=`curl -s "localhost:7070/api/v3/column/m.sn?m.ip=${2}" |grep "m.sn" |awk -F'"' '{print $4}'`
    docker exec `docker ps |grep oob  |awk '{print $1}'` grep ${msn} /tmp/sn_ip_map ;;
    sr)
    curl -s "localhost:7070/api/v3/column/m.sr.id,m.ip?m.idc=am86"|grep -B1 -i ${2} ;;
    sql)
    curl -s http://localhost:7070/api/v3/column/service.res.result|awk -F'": "' '/db_password/{print $2}'|awk -F'"' '/"'$2'/{s="mysql -h"$40" -u"$36" -p"$4" -D"$44" -P"$12;gsub("\\\\","",s);print s}' ;;
    machine)
    curl -s "localhost:7070/api/v3/column/m.*?m.${2}=${3}" ;;
    slb)
    ssh 20.15.0.5 "ipvsadm -lnv |grep  -A 5 ${2}" ;;
    *)
    printing ;;
    esac
}
function printing() {

    echo "Usage: ruiapi [OPTION] PATTERN ...
Search for PATTERN in API.
  oob        , search oob_ip by sn in oob_container
  serverrole , search vm_ip by serverrole_name
  sql        , search the way of login by db_name
  machine    , search machine_info by PATTERN(up to need)
  slb        , search real_server by slb_ip
               
Example:
  ruiapi oob 10.15.100.100
  ruiapi sr tongque_nginx
  ruiapi sql dbaas
  ruiapi machine ip 10.15.100.100
  ruiapi slb 10.15.100.110
                         
Report bugs to <ex-ruidongdong@suzhoubank.com>.  "
}

ops $@

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值