java要多思考下

          成長(zhǎng)^_^

             ::  :: 新隨筆 ::  ::  :: 管理 ::
            33 隨筆 :: 0 文章 :: 19 評(píng)論 :: 0 Trackbacks
          取腳本運(yùn)行參數(shù): $0 $1 $2 ...
          取腳本運(yùn)行參數(shù)個(gè)數(shù): $#
          取腳本運(yùn)行的所有參數(shù):$*
          判斷字符串相等:if [[ "$1" = "-cmd" ]]; then command=$2 fi ([后有空格,]前也有空格)
          變量命名:string1="/usr/local/redis/bin/redis-cli"
          取變量值:$string1
          命令調(diào)用:`export abc="abc"`
          字符串命令調(diào)用:result=`eval $string`
          將命令調(diào)用值賦給數(shù)組:results=(`eval $string`)
          取數(shù)組長(zhǎng)度:${#results[@]}
          取數(shù)組值:${results[i]}
          取運(yùn)行參數(shù)數(shù)組值:${!i}
          調(diào)用外部腳本:. xxxx.sh

          附:redis數(shù)據(jù)批量操作腳本
          #!/bin/bash
          command="keys '*'"
          action="noaction"
          redis_cli="/usr/local/redis/bin/redis-cli"

          if [[ "$1" = "-cmd" ]]; then
              command=$2
          fi

          if [[  "$3" = "-act"  ]]; then
              action=$4
          fi

          #collect the command result to an array named results
          echo "=====> do command: $command"
          exec_command="$redis_cli $command"
          results=(`eval $exec_command`)

          if [[ ${#results[@]} = 0 ]];then
              exit 1
          fi

          for (( i = 0; i < ${#results[@]}; i++ )); do
              case $action in
                  del)
                      doaction="$redis_cli del ${results[i]}"
                      ;;
                  ttl)
                      doaction="$redis_cli ttl ${results[i]}"
                      ;;
                  expire)
                      doaction="$redis_cli expire ${results[i]} 60"
                      ;;
                  *)
                      doaction="echo \"${results[i]}\""
                      ;;
              esac
              
              actionResult=`eval $doaction`
              echo "=====> do action: $doaction ==> result: $actionResult"
          done

          調(diào)用形式:
          ./xxxx.sh
          ./xxxx.sh -cmd 'keys aa*'
          ./xxxx.sh -cmd 'keys aa*' -act del
          ./xxxx.sh -cmd 'keys aa*' -act expire
          ./xxxx.sh -cmd 'keys aa*' -act ttl

           
          posted on 2013-02-22 17:50 java要多思考下 閱讀(1796) 評(píng)論(0)  編輯  收藏 所屬分類(lèi): 系統(tǒng)運(yùn)維
          主站蜘蛛池模板: 永兴县| 屯门区| 合作市| 迁安市| 彭州市| 靖安县| 永福县| 沿河| 民县| 东平县| 秭归县| 彭山县| 安宁市| 琼中| 新闻| 玛多县| 同仁县| 五华县| 乐业县| 罗甸县| 寿光市| 张家口市| 哈巴河县| 昔阳县| 广南县| 阿拉善左旗| 太湖县| 和政县| 滁州市| 盐池县| 杭锦旗| 贞丰县| 牡丹江市| 兴仁县| 安塞县| 唐山市| 黄骅市| 光泽县| 万州区| 新竹县| 连山|