爆款云主机2核4G限时秒杀,88元/年起!
查看详情

活动

天翼云最新优惠活动,涵盖免费试用,产品折扣等,助您降本增效!
热门活动
  • 618智算钜惠季 爆款云主机2核4G限时秒杀,88元/年起!
  • 免费体验DeepSeek,上天翼云息壤 NEW 新老用户均可免费体验2500万Tokens,限时两周
  • 云上钜惠 HOT 爆款云主机全场特惠,更有万元锦鲤券等你来领!
  • 算力套餐 HOT 让算力触手可及
  • 天翼云脑AOne NEW 连接、保护、办公,All-in-One!
  • 中小企业应用上云专场 产品组合下单即享折上9折起,助力企业快速上云
  • 息壤高校钜惠活动 NEW 天翼云息壤杯高校AI大赛,数款产品享受线上订购超值特惠
  • 天翼云电脑专场 HOT 移动办公新选择,爆款4核8G畅享1年3.5折起,快来抢购!
  • 天翼云奖励推广计划 加入成为云推官,推荐新用户注册下单得现金奖励
免费活动
  • 免费试用中心 HOT 多款云产品免费试用,快来开启云上之旅
  • 天翼云用户体验官 NEW 您的洞察,重塑科技边界

智算服务

打造统一的产品能力,实现算网调度、训练推理、技术架构、资源管理一体化智算服务
智算云(DeepSeek专区)
科研助手
  • 算力商城
  • 应用商城
  • 开发机
  • 并行计算
算力互联调度平台
  • 应用市场
  • 算力市场
  • 算力调度推荐
一站式智算服务平台
  • 模型广场
  • 体验中心
  • 服务接入
智算一体机
  • 智算一体机
大模型
  • DeepSeek-R1-昇腾版(671B)
  • DeepSeek-R1-英伟达版(671B)
  • DeepSeek-V3-昇腾版(671B)
  • DeepSeek-R1-Distill-Llama-70B
  • DeepSeek-R1-Distill-Qwen-32B
  • Qwen2-72B-Instruct
  • StableDiffusion-V2.1
  • TeleChat-12B

应用商城

天翼云精选行业优秀合作伙伴及千余款商品,提供一站式云上应用服务
进入甄选商城进入云市场创新解决方案
办公协同
  • WPS云文档
  • 安全邮箱
  • EMM手机管家
  • 智能商业平台
财务管理
  • 工资条
  • 税务风控云
企业应用
  • 翼信息化运维服务
  • 翼视频云归档解决方案
工业能源
  • 智慧工厂_生产流程管理解决方案
  • 智慧工地
建站工具
  • SSL证书
  • 新域名服务
网络工具
  • 翼云加速
灾备迁移
  • 云管家2.0
  • 翼备份
资源管理
  • 全栈混合云敏捷版(软件)
  • 全栈混合云敏捷版(一体机)
行业应用
  • 翼电子教室
  • 翼智慧显示一体化解决方案

合作伙伴

天翼云携手合作伙伴,共创云上生态,合作共赢
天翼云生态合作中心
  • 天翼云生态合作中心
天翼云渠道合作伙伴
  • 天翼云代理渠道合作伙伴
天翼云服务合作伙伴
  • 天翼云集成商交付能力认证
天翼云应用合作伙伴
  • 天翼云云市场合作伙伴
  • 天翼云甄选商城合作伙伴
天翼云技术合作伙伴
  • 天翼云OpenAPI中心
  • 天翼云EasyCoding平台
天翼云培训认证
  • 天翼云学堂
  • 天翼云市场商学院
天翼云合作计划
  • 云汇计划
天翼云东升计划
  • 适配中心
  • 东升计划
  • 适配互认证

开发者

开发者相关功能入口汇聚
技术社区
  • 专栏文章
  • 互动问答
  • 技术视频
资源与工具
  • OpenAPI中心
开放能力
  • EasyCoding敏捷开发平台
培训与认证
  • 天翼云学堂
  • 天翼云认证
魔乐社区
  • 魔乐社区

支持与服务

为您提供全方位支持与服务,全流程技术保障,助您轻松上云,安全无忧
文档与工具
  • 文档中心
  • 新手上云
  • 自助服务
  • OpenAPI中心
定价
  • 价格计算器
  • 定价策略
基础服务
  • 售前咨询
  • 在线支持
  • 在线支持
  • 工单服务
  • 建议与反馈
  • 用户体验官
  • 服务保障
  • 客户公告
  • 会员中心
增值服务
  • 红心服务
  • 首保服务
  • 客户支持计划
  • 专家技术服务
  • 备案管家

了解天翼云

天翼云秉承央企使命,致力于成为数字经济主力军,投身科技强国伟大事业,为用户提供安全、普惠云服务
品牌介绍
  • 关于天翼云
  • 智算云
  • 天翼云4.0
  • 新闻资讯
  • 天翼云APP
基础设施
  • 全球基础设施
  • 信任中心
最佳实践
  • 精选案例
  • 超级探访
  • 云杂志
  • 分析师和白皮书
  • 天翼云·创新直播间
市场活动
  • 2025智能云生态大会
  • 2024智算云生态大会
  • 2023云生态大会
  • 2022云生态大会
  • 天翼云中国行
天翼云
  • 活动
  • 智算服务
  • 产品
  • 解决方案
  • 应用商城
  • 合作伙伴
  • 开发者
  • 支持与服务
  • 了解天翼云
      • 文档
      • 控制中心
      • 备案
      • 管理中心

      【shell】循环测试脚本|历史脚本记录|启动OSD脚本

      首页 知识中心 软件开发 文章详情页

      【shell】循环测试脚本|历史脚本记录|启动OSD脚本

      2025-02-14 08:20:10 阅读次数:27

      awk,ceph,echo,grep,line

      启动OSD脚本 

      #ps -ef | grep fio | grep -v grep | awk '{print $2}' | xargs kill -s 9
      rm -rf /var/log/ceph/ceph-osd.*.log
      rm -rf /var/run/ceph/ceph-adm*
      rm -rf /var/run/ceph/ceph-osd.*

      if [ -z $1 ] ; then
        echo "******************"
        echo "Please input host number:"
        echo "61? 62? 63? ……"
        echo "******************"
        exit 
      else
         HOST_NUM=$1
         echo "Start host${HOST_NUM}'s osd demon."
      fi


      CEPH_OSD=/opt/h3c/bin/ceph-osd


      ceph osd tree|awk -v flag=0 '
      /host rdma'$HOST_NUM'/ {flag=1; next}
      flag == 1 && /host rdma/ {flage=0; exit}
      flag == 1 {${CEPH_OSD} --cluster=ceph -i $1 -f --setuser ceph --setgroup ceph > "osd"$1".log" 2>&1 &}'

      ps -aux|grep ceph-osd
      echo "total is:"`ps -aux|grep ceph-osd|grep -v 'grep'|wc -l`
       

      循环测试脚本 

      #!/bin/bash


      #说明函数定义脚本

      #***************************************************************
      #函数 status_check
      #判断程序$1是否已经在运行  $1:第一个参数
      #***************************************************************
      function status_check()
      {

          pids=`ps aux|grep -w ${1}|grep -v grep|awk '{print $2}'|head -1` #获取${1}进程号grep -w ${1}:匹配第一个参数单词的行;grep -v grep:去掉含grep的行,awk '{print $2}':取行的第二列(进程号),head -1:(多个同名进程时)只取第一行
          #pids=pidof ${1}|awk '{print $1}' #获取${1}进程号,awk '{print $1}' 有多个同名的进程时,取第一个(第一列)
          
          if [ ${pids} ]

              then
              echo ${1}' running'   
              return 1

          else
              echo ${1}' not running'
              return 2
          fi

      }


      #
      #***************************************************************
      #函数 stop()
      #停止$1 
      #***************************************************************
      function stop()
      {
      TRY=1
      while true; do
          status_check ${1}
          
          if [ $? -ne 1 ]  #-ne:不等于

              then
              
              echo ${1}' stoped'

                 break
          else

              ps aux|grep -w ${1}|grep -v grep|awk '{print $2}'|xargs kill -15 #-w ${1} 仅完全匹配字词${1}(既参数1),grep -v grep”是在列出的进程中去除含有关键字“grep”的进程,awk '{print $2}'取行的第二列(进程号),
                                                                                   #“xargs kill -15”中的xargs命令是用来把前面命令的输出结果(PID)作为“kill -15”命令的参数,并执行该命令。kill发信号-15给进程,进程释放资源后退出,发-9给进程则强制退出
               echo ' stop ' ${1}

            fi

                sleep 5
          done

       }

      #--------------------------------------------------------------------------


      TEST_NUM=3
      ONE_RESULT="./test_one_relt.txt"
      RESULTS="./test_relt.txt"
      FIND_STR="Total op"
      CHECK_INTERVAL=5
      waittime=0

      for((i=1;i<=${TEST_NUM};i++)) 
      do
          waittime=0
          echo "现在时间:`date '+%Y-%m-%d %H:%M:%S'`"  
          echo "NO.${i} test start."

          rm -rf ${ONE_RESULT}
          ./ceph_perf_msgr_client  172.17.31.54:12345 1 1 100 10 40960 &> ${ONE_RESULT} &
         
          while [[ `grep -c "${FIND_STR}" ${ONE_RESULT}` -eq '0' ]]; do

              echo "Test not finished,continue to wait. ${waittime}s"

              sleep ${CHECK_INTERVAL}

               ((waittime+=${CHECK_INTERVAL}))

          done
        
        echo "NO.${i} test finished."
        cat ${ONE_RESULT} >> ${RESULTS}
        stop ceph_perf_msgr_client
        
        echo " "
        echo " "

      done

      cat ${RESULTS} |grep 'run time'

      ((i--))
      echo "${i}/${TEST_NUM} Test finished."
       

      获取device name、ib_port、gid index 、mtu的脚本

      获取intel or mellonx 的device name、ib_port、gid index 、mtu的脚本

      用法:get-rdma-device-info  eth0

       

      #!/bin/bash
      
      g_vendor=""
      g_hexip=""
      g_nic_name=""
      
      
      MY_UUID=$(cat /proc/sys/kernel/random/uuid)
      MY_TMP_FILE_PATH=/tmp/${MY_UUID}.txt
      MY_LOG_FILE_PATH=/var/ceph_osd_get_rdma_info.log
      
      
      #mellonx or intel
      function  set_vendor()
      {
      
       vendor_id=`ibv_devinfo|grep "vendor_id"|awk 'NR==1 {print $2}'`
      
      
      if [[ "0x8086" = ${vendor_id} ]]; then
      
           g_vendor="INTEL"
      
      elif [[ "0x02c9" = ${vendor_id} ]]; then
      
           g_vendor="MELLONX"
      else
      
      echo "unknown rdma hca vendor." >>${MY_LOG_FILE_PATH}
      
      exit 1
      
      fi
      
      }
      
      
      #ip4 to hex ip
      function ip4_to_hex()
      {
      tmpifs=${IFS}
      
      IFS="."
      num=0
      
      for str in $1
      do
      ip[num]=${str}
      ((num++))
      done
      
      g_hexip=`printf "%x%x:%x%x" ${ip[0]} ${ip[1]} ${ip[2]} ${ip[3]}`
      
      IFS=${tmpifs}
      }
      
      
      #intel hca process
      #reference:https:///30368/eng/README_irdma_1.4.22.txt
      function  intel_hca()
      {
      echo "vendor is intel">>${MY_LOG_FILE_PATH}
      
      
      devices=`ibv_devices|awk 'NR > 2 {print $1}'`
      
      for dev in $devices
      do
      ifname=`ls /sys/class/infiniband/${dev}/device/net`
      if [[ ${g_nic_name} = ${ifname} ]];then
      device_name=${dev}
      fi
      done
      
      ethip=`ip route|grep 'link src'|grep ${g_nic_name}|awk '{print $9}'`
      
      ip4_to_hex ${ethip}
      
      
      if [ "X${device_name}" != "X" ];then
        echo "device_name"=${device_name} >>${MY_TMP_FILE_PATH}
      else
        echo "get device_name failed">>${MY_LOG_FILE_PATH}
        exit 1
      fi
      
      
      for port in ` ls /sys/class/infiniband/${device_name}/ports/`
      {
          for gidx in `ls /sys/class/infiniband/${device_name}/ports/${port}/gids`
          {
          	hca_hex_ip=`cat /sys/class/infiniband/${device_name}/ports/${port}/gids/${gidx}`
           
           	if [[ ${hca_hex_ip} =~ ${g_hexip} ]];then
           		gid_index=${gidx}
           		ib_port=${port}
           	fi
      
           }
      }
      
      
      if [ "X${gid_index}" != "X" ];then
        echo "gid_index"=${gid_index} >>${MY_TMP_FILE_PATH}
      else
        echo "get gid_index failed">>${MY_LOG_FILE_PATH}
        exit 1
      fi
      
      
      if [ "X${ib_port}" != "X" ];then
        echo "ib_port"=${ib_port} >>${MY_TMP_FILE_PATH}
      else
        echo "get ib_port failed">>${MY_LOG_FILE_PATH}
        exit 1
      fi
      
      mtu_index=`ibv_devinfo|grep -A 17 ${device_name} |grep active_mtu|awk '{print $3}'|awk -F "[()]" '{print $2}'`
      
      if [ "X${mtu_index}" != "X" ];then
        echo "mtu_index"=${mtu_index} >>${MY_TMP_FILE_PATH}
      else
        echo "get mtu_index failed">>${MY_LOG_FILE_PATH}
        exit 1
      fi
      
      }
      
      
      
      #mellonx hca process
      #ibdev2netdev、show_gids
      function  mellonx_hca()
      {
      
      echo "vendor is mellonx">>${MY_LOG_FILE_PATH}
      
      device_name=`ibdev2netdev | grep -w ${g_nic_name} | awk -F ' ' '{print $1}'`
      
      if [ "X$device_name" != "X" ];then
        echo "device_name"=${device_name} >>${MY_TMP_FILE_PATH}
      else
        echo "get device_name failed">>${MY_LOG_FILE_PATH}
        exit 1
      fi
      
      
      gid_index=`show_gids | grep -w ${device_name} |grep -w "v2"| awk -F ' ' '$5 !="" {print $3}'|head -n 1`
      
      if [ "X${gid_index}" != "X" ];then
        echo "gid_index"=${gid_index} >>${MY_TMP_FILE_PATH}
      else
        echo "get gid_index failed">>${MY_LOG_FILE_PATH}
        exit 1
      fi
      
      ib_port=`show_gids | grep -w ${device_name} |grep -w "v2"| awk -F ' ' '$5 !="" {print $2}'|head -n 1`
      
      if [ "X${ib_port}" != "X" ];then
        echo "ib_port"=${ib_port} >>${MY_TMP_FILE_PATH}
      else
        echo "get ib_port failed">>${MY_LOG_FILE_PATH}
        exit 1
      fi
      
      mtu_index=`ibv_devinfo|grep -A 17 ${device_name} |grep active_mtu|awk '{print $3}'|awk -F "[()]" '{print $2}'`
      
      if [ "X${mtu_index}" != "X" ];then
        echo "mtu_index"=${mtu_index} >>${MY_TMP_FILE_PATH}
      else
        echo "get mtu_index failed">>${MY_LOG_FILE_PATH}
        exit 1
      fi
      
      }
      
      
      
      
      
      #====================================================================
      #start shell
      #====================================================================
      
      
      echo "input interface name is:$1">${MY_LOG_FILE_PATH}
      
      if [ "X$1" == "X" ]; then
        echo "interface is not specific,excample:$0 eth0">>${MY_LOG_FILE_PATH}
        exit 1
      fi
      
      g_nic_name=$1
      
      is_virtual=`ls -l /sys/class/net/ | grep " $g_nic_name " | grep "\/virtual\/net\/" | wc -l`
      if [ $is_virtual -ne 0 ]; then
        g_nic_name=`echo $g_nic_name | awk -F "." 'OFS="." {$NF="" ;print $0}' | sed 's/.$//'`
      fi
      
      
      set_vendor
      
      
      if [[ "INTEL" = ${g_vendor} ]]; then
      
      	intel_hca
      
      elif [[ "MELLONX" = ${g_vendor} ]]; then
      
      	mellonx_hca
      else
      
      echo "Unable to determine the vendor. exit 1">>${MY_LOG_FILE_PATH}
      exit 1   
      
      fi
      
      cat ${MY_TMP_FILE_PATH}
      
      rm -f ${MY_TMP_FILE_PATH}
      
      

      读取某个 device的信息,获取里面某些参量的数值

      #/bin/bash
      set -e
      
      function get_param()
      {
      if   [[ ${1} =~ "max_sge:" ]];then
          echo "in here"
          max_sge=`echo ${1}|awk '{print $2}'`
      elif [[ ${1} =~ "sm_lid:" ]];then
          sm_lid=`echo ${1}|awk '{print $2}'`
      
      elif [[ ${1} =~ "max_srq:" ]];then
          max_srq=`echo ${1}|awk '{print $2}'`
          echo "in here2"
      fi
      }
      
      #----------------main--------------------------
      
      devicename=${1} #hca_id
      foundflag=0
      MY_UUID=$(cat /proc/sys/kernel/random/uuid)
      MY_TMP_FILE_PATH=/tmp/${MY_UUID}.txt
      
      
      if [ "X${devicename}" == "X" ];then
        echo "Please input provide devicename!" 
        exit 1
      fi
      
      ibv_devinfo >> ${MY_TMP_FILE_PATH}
      
      
      while read line
      do
      
      if   [[ "${line}" =~ "${devicename}" ]];then
            foundflag=1
      elif  [[ ${foundflag} -eq 1 ]] && [[ "${line}" =~ "hca_id:" ]];then
      	  echo "finish"
      	  break	  
      fi
      
      if   [[ ${foundflag} -eq 1 ]];then
      get_param "$line"
      fi
      
      done < ${MY_TMP_FILE_PATH}
      
      echo "max_sge=" $max_sge
      echo "max_srq=" $max_srq
      echo "sm_lid=" $sm_lid

       

      自动根据ceph.conf 中的public和cluster IP 配置RDMA的参数

       

      ms_async_rdma_devicename_portnum_gidindex_use_config = true
      ms_async_rdma_front_device_name = 
      ms_async_rdma_back_device_name = 
      ms_async_rdma_front_device_port_num = 1
      ms_async_rdma_back_device_port_num = 1
      ms_async_rdma_front_device_gid_idx = 
      ms_async_rdma_back_device_gid_idx = 
       

       

      #/bin/bash
      set -e
      CEPH_CONF=/etc/ceph/ceph.conf
      g_vendor=""    #vendor intel or mellonx
      g_hexip=""     #ip in hex 
      #g_nic_name=$1  #netwok interface
      device_name="" #rdma device name
      
      
      #mellonx or intel
      function  get_vendor()
      {
        vendor_id=` ibv_devinfo|grep "vendor_id"|awk 'NR==1 {print $2}'`
      
        if [[ "0x8086" = ${vendor_id} ]]; then
           g_vendor="INTEL"
           echo "vendor is intel"
        elif [[ "0x02c9" = ${vendor_id} ]]; then
           g_vendor="MELLONX"
           echo "vendor is mellonx"
        else
           echo "unknown rdma hca vendor." 
          exit 1
        fi
      }
      
      #ip4 to hex ip
      function ip4_to_hex()
      {
      
      tmpifs=${IFS}
      
      IFS="."
      ipf1=`echo $1|awk '{print $1}'`
      ipf2=`echo $1|awk '{print $2}'`
      ipf3=`echo $1|awk '{print $3}'`
      ipf4=`echo $1|awk '{print $4}'`
      
      IFS=${tmpifs}
      
      g_hexip=`printf "%x%x:%x%x" ${ipf1} ${ipf2} ${ipf3} ${ipf4}`
       echo "ip:"$1 
       echo "hexip:"$g_hexip 
      
      }
      
      function get_rdma_device_name()
      {
      
        if [[ "INTEL" = ${g_vendor} ]]; then
            devices=` ibv_devices| awk 'NR > 2 {print $1}'`
      
            for dev in $devices
            do
              ifname=` ls /sys/class/infiniband/${dev}/device/net`
              if [[ ${g_nic_name} = ${ifname} ]];then
                device_name=${dev}
                echo "device_name="${device_name}  #out put to C++ stream  who call this shell
                break
              fi
            done
        elif [[ "MELLONX" = ${g_vendor} ]]; then
           device_name=` ibdev2netdev | grep -w ${g_nic_name} | awk -F ' ' '{print $1}'`
           echo "device_name="${device_name} #out put to C++ stream  who call this shell
        else
           echo "Unable to determine the vendor. exit 1"
          exit 1   
        fi
        if [ "X$device_name" == "X" ];then
           echo "get device_name failed!Please check whether the provided IP is RDMA interface's IP."
          exit 1
        fi
      }
      
      
      function get_port_num_and_gid_idx()
      {
      
        #ethip=` ip route|grep 'link src'|grep ${g_nic_name}|head -n 1|awk '{print $9}'`
        ip4_to_hex ${ethip}
      
        if [[ "INTEL" = ${g_vendor} ]]; then
          for port in ` ls /sys/class/infiniband/${device_name}/ports/`
          {
              for gidx in ` ls /sys/class/infiniband/${device_name}/ports/${port}/gids`
              {
                hca_hex_ip=` cat /sys/class/infiniband/${device_name}/ports/${port}/gids/${gidx}`
                if [[ ${hca_hex_ip} =~ ${g_hexip} ]];then
                  gid_index=${gidx}
                  port_num=${port}
                  echo "gid_index="${gid_index} #out put to C++ stream  who call this shell
                  echo "port_num="${port_num} #out put to C++ stream  who call this shell
                  ip_found=true
                  break 2
                fi
              }
          }
      
          if [ "true" != $ip_found ];then
            echo "get port_num /gid_index failed"
      	  exit 1 
          fi
        elif [[ "MELLONX" = ${g_vendor} ]]; then
          gid_index=` show_gids | grep -w ${device_name} |grep -w "v2"|grep ${ethip}| awk '{print $3}'`
          port_num=` show_gids | grep -w ${device_name} |grep -w "v2"|grep ${ethip}| awk '{print $2}'`
          echo "gid_index="${gid_index} #out put to C++ stream  who call this shell
          echo "port_num="${port_num} #out put to C++ stream  who call this shell
        else
           echo "Unable to determine the vendor. exit 1"
          exit 1
        fi
      
        if [ "X${gid_index}" == "X" ];then
          echo "get gid_index failed" 
          exit 1
        fi
        if [ "X${port_num}" == "X" ];then
          echo "get port_num failed"
          exit 1
        fi
      }
      
      function parse_device_global_param()
      {
        if [[ ${1} =~ "max_sge:" ]];then
          max_sge=`echo ${1}|awk '{print $2}'`
          echo "max_sge="${max_sge} #out put to C++ stream  who call this shell
        elif [[ ${1} =~ "max_qp_wr:" ]];then
          max_qp_wr=`echo ${1}|awk '{print $2}'`
          echo "max_qp_wr="${max_qp_wr}
        elif [[ ${1} =~ "max_srq:" ]];then
          max_srq=`echo ${1}|awk '{print $2}'`
          echo "max_srq="${max_srq} #out put to C++ stream  who call this shell
        fi
      }
      
      
      function parse_device_port_param()
      {
        if [[ ${1} =~ "active_mtu:" ]];then
          mtu_index=`echo ${1}|awk '{print $3}'|cut -d "(" -f 2|cut -d ")" -f 1 `
          echo "mtu_index="${mtu_index} #out put to C++ stream  who call this shell
        elif [[ ${1} =~ "sm_lid:" ]];then
          sm_lid=`echo ${1}|awk '{print $2}'`
          echo "sm_lid="${sm_lid} #out put to C++ stream  who call this shell
        elif [[ ${1} =~ "sm_sl:" ]];then
          sm_sl=`echo ${1}|awk '{print $2}'`
          echo "sm_sl="${sm_sl} #out put to C++ stream  who call this shell
        fi
      }
      
      
      #----------------main--------------------------
      
      #====================================main=======================
      
      #must get vendor first
      get_vendor
      
      #delete 
      sed -i "/ms_async_rdma_devicename_portnum_gidindex_use_config/d" $CEPH_CONF
      #add  xxxx after ms_cluster_type
      sed -i "/ms_cluster_type/a\ms_async_rdma_devicename_portnum_gidindex_use_config = true" $CEPH_CONF
      
      #get public  rdma info >>>>>>>>>>>>>>>>>>>>>
      echo "get public  rdma info >>>>>>>>>>>>>>>>>>>>>"
      
      ethip=$(line=`cat $CEPH_CONF |grep -E 'public_addr'`&&echo ${line#*=})
      g_nic_name=$(ifconfig | awk -F ":" '/'$ethip'/{print a}{a=$1}')
      
      if [ "X${ethip}" == "X" ];then
        echo "Please input provide ip!" 
        exit 1
      fi
      
      #get rdma device name by eth interface
      get_rdma_device_name
      #get rdma port num and gid index by device name
      get_port_num_and_gid_idx
      
      #now we have the device name and port ,so we can get more attr from "ibv_devinfo -v" 
      
      #<-------------------------get device's info line
      #put  devinfo to tmp file1 
       ibv_devinfo -d ${device_name} -i ${port_num} -v|while read line
      do
        #get device's global param
        parse_device_global_param "$line"
        #get device's specify port's param
        parse_device_port_param "${line}"
      done 
      
      #delete
      sed -i "/ms_async_rdma_front_device_name/d" $CEPH_CONF
      sed -i "/ms_async_rdma_front_device_port_num/d" $CEPH_CONF
      sed -i "/ms_async_rdma_front_device_gid_idx/d" $CEPH_CONF
      #add  xxxx after ms_async_rdma_devicename_portnum_gidindex_use_config
      sed -i "/ms_async_rdma_devicename_portnum_gidindex_use_config/a\ms_async_rdma_front_device_name=$device_name" $CEPH_CONF
      sed -i "/ms_async_rdma_devicename_portnum_gidindex_use_config/a\ms_async_rdma_front_device_port_num=$port_num" $CEPH_CONF
      sed -i "/ms_async_rdma_devicename_portnum_gidindex_use_config/a\ms_async_rdma_front_device_gid_idx=$gid_index" $CEPH_CONF
      
      #get cluster  rdma info >>>>>>>>>>>>>>>>>>>>>
      echo "get cluster  rdma info >>>>>>>>>>>>>>>>>>>>>"
      
      ethip=$(line=`cat /etc/ceph/ceph.conf |grep -E 'cluster_addr'`&&echo ${line#*=})
      g_nic_name=$(ifconfig | awk -F ":" '/'$ethip'/{print a}{a=$1}')
      
      if [ "X${ethip}" == "X" ];then
        echo "Please input provide ip!" 
        exit 1
      fi
      
      #get rdma device name by eth interface
      get_rdma_device_name
      #get rdma port num and gid index by device name
      get_port_num_and_gid_idx
      
      #now we have the device name and port ,so we can get more attr from "ibv_devinfo -v" 
      
      #<-------------------------get device's info line
      #put  devinfo to tmp file1 
       ibv_devinfo -d ${device_name} -i ${port_num} -v|while read line
      do
        #get device's global param
        parse_device_global_param "$line"
        #get device's specify port's param
        parse_device_port_param "${line}"
      done 
      
      
      #delete
      sed -i "/ms_async_rdma_back_device_name/d" $CEPH_CONF
      sed -i "/ms_async_rdma_back_device_port_num/d" $CEPH_CONF
      sed -i "/ms_async_rdma_back_device_gid_idx/d" $CEPH_CONF
      #add  xxxx after ms_async_rdma_devicename_portnum_gidindex_use_config
      sed -i "/ms_async_rdma_devicename_portnum_gidindex_use_config/a\ms_async_rdma_back_device_name=$device_name" $CEPH_CONF
      sed -i "/ms_async_rdma_devicename_portnum_gidindex_use_config/a\ms_async_rdma_back_device_port_num=$port_num" $CEPH_CONF
      sed -i "/ms_async_rdma_devicename_portnum_gidindex_use_config/a\ms_async_rdma_back_device_gid_idx=$gid_index" $CEPH_CONF
      
      
      echo "get_success=true"
      
      #excample:
      
      #[root@rdma59 perf5.0]# ibv_devinfo 
      #hca_id: rocep216s0f0
      #        transport:                      InfiniBand (0)
      #        fw_ver:                         1.54
      #        node_guid:                      b696:91ff:fea5:9a70
      #        sys_image_guid:                 b496:91a5:9a70:0000
      #        vendor_id:                      0x8086
      #        vendor_part_id:                 5523
      #        hw_ver:                         0x2
      #       phys_port_cnt:                  1
      #             port:   1
      #                    state:                  PORT_ACTIVE                                                                                                       (4)
      #                    max_mtu:                4096 (5)
      #                  	 active_mtu:             1024 (3)
      #                  	 sm_lid:                 0
      #                    port_lid:               1
      #                    port_lmc:               0x00
      #                    link_layer:             Ethernet
      #
      #hca_id: rocep216s0f1
      #        transport:                      InfiniBand (0)
      #        fw_ver:                         1.54
      #        node_guid:                      b696:91ff:fea5:9a71
      #        sys_image_guid:                 b496:91a5:9a71:0000
      #        vendor_id:                      0x8086
      #        vendor_part_id:                 5523
      #        hw_ver:                         0x2
      #        phys_port_cnt:                  1
      #	        port:   1
      #					state:                  PORT_DOWN (1                                                                                                      )
      #					max_mtu:                4096 (5)
      #					active_mtu:             1024 (3)
      #					sm_lid:                 0
      #					port_lid:               1
      #					port_lmc:               0x00
      #					link_layer:             Ethernet
      
      

       

      保持空间/删除旧文件

      写脚本keepspace.sh然后配置crontab 定时执行。

      仿照下面例子在/etc/crontab 中添加定时任务

      */1 * * * *      /usr/local/keepspace.sh

       

      因为crontab最小定时单位是1分钟,如果想让脚本每5秒执行一次,则再写脚本crontab.sh,然后配置crontab

      #!/bin/bash
      step=5     

      for (( i = 0; i < 60; i=(i+step) )); do

      echo `/bin/date`" /etc/crontab delete corefile" >> /corefile/delete_recored.txt

      /usr/local/bin/keepspace.sh

      sleep $step
      done
      exit 0
       

      */1 * * * *     /usr/local/crontab.sh

      keepspace.sh


      yuzhi=50
      FileDir=/corefile

      function delete()
      {

      ls ${FileDir} -rt |while read line
      do
      OldFile=${line}
      echo $date "Delete File:"$OldFile
      rm -rf $FileDir/$OldFile
      spaceleft=`df |grep -w "/"|awk '{print $5}'|tr -cd "[0-9]"`;

      if [ $spaceleft -lt ${yuzhi} ];then

      echo "finsh"
      break
      fi
      done

      }


      while :
      do
      spaceleft=`df |grep -w "/"|awk '{print $5}'|tr -cd "[0-9]"`;

      if [ $spaceleft -gt ${yuzhi} ];then

      echo "big"
      delete

      else

      echo "small"
      break

      fi

      done

       

       上面的脚本用df,文件系统坏了df可能会卡住,换下面的脚本,比上面的脚本需要配置磁盘总空间totalspace=390 #G

      keepspace.sh

      yuzhi=50
      FileDir=/corefile
      totalspace=390 #G

       

      function count_used()
      {

      total=0
      num=0

      for line in `ls -lh ${FileDir} |grep "/*G"|awk '{print $5}'`

      do

      num=$( echo $line|tr -cd "[0-9]")
       echo $num
      total=$((total+num))
      done

      used=$((100*total/totalspace))
      echo $used

      }

      function delete()
      {

      ls ${FileDir} -rt |while read line
      do
      OldFile=${line}
      echo $date "Delete File:"$OldFile
      rm -rf $FileDir/$OldFile

      count_used

      if [ $used -lt ${yuzhi} ];then

      echo "finsh"
      break
      fi
      done

      }


      while :
      do

      count_used

      if [ $used -gt ${yuzhi} ];then

      echo "need to delete"
      #delete

      else

      echo "no need to delete"
      break

      fi

      done

      多个单元,取某个单元的参数

      #<-------------------------get device's info line
      #put  devinfo to tmp file1 
      ibv_devinfo -v >> ${MY_TMP_FILE_PATH}

      #get the specify device ${devicename} devinfo ,put into tmp file2
      #the specify device devinfo is between "hca_id:"<-->"hca_id:",or "hca_id:" to the end
      founddevice=0
      while read line
      do
      if   [[ "${line}" =~ "${devicename}" ]];then
            #found the first "hca_id: devicename"
            founddevice=1
      elif  [[ ${founddevice} -eq 1 ]] && [[ "${line}" =~ "hca_id:" ]];then
            #found the next by "hca_id: devicenamexx",only the line between  "hca_id: devicename"<--->"hca_id: devicenamexx" is what we need
            #so end.
            echo "finish"
            break      
      fi

      if   [[ ${founddevice} -eq 1 ]];then
       echo "$line" >> ${MY_TMP_FILE_PATH2} #put the line between  "hca_id: devicename"<--->"hca_id: devicenamexx" into tmp file2
      fi

      done < ${MY_TMP_FILE_PATH}

       

      给用户SDS_Admin做免密登录 

      #!/bin/bash
      #把本机的公钥拷贝到/etc/ceph/ceph.conf 中 all_manage_ip 指定的所以IP的主机上
      
      line=`cat /etc/ceph/ceph.conf |grep -E 'all_manage_ip'`&&HOSTS=$(echo ${line#*=}|sed s/[[:space:]]//g)
      
      OLD_IFS="$IFS"   #备份原值
      IFS=","     #设分隔符为“,”
      
      for ip_addr in ${HOSTS}
      do
          echo "$ip_addr"
          ip_addr=$ip_addr expect << 'EOS'
            set timeout 10
            spawn ssh-copy-id  SDS_Admin@$::env(ip_addr)
            expect "*password*"
            send "Admin@123stor\r"
            expect eof; 
            #exit 0
      EOS
      done
      IFS="$OLD_IFS"

      数组处理

      将ls命令返回值存入数组

      (转自:https:///rgndao/article/details/126752271)

       arr=(`ls`)

      输出数组个数echo ${#arr[*]}

       

      这个问题一开始困扰到我了,ls的返回值是一个以空格为分隔符的长字符串,而shell里又没有像python一样方便的字符串split操作,没办法一步拆分,难道就只能写在循环里一步步赋值了么?

      后来,我偶然发现shell里数组的定义方式为:

      array_name=(value1 value2 ... valuen)
      参数本身就是以空格分隔的!那不正好,我们只需要在ls返回值的外面套上一层圆括号就好,例如这样

       arr=(`ls`)
      接下来你可以试试输出arr的元素个数,看是不是成功将目录名存储为了数组

      echo ${#arr[*]}

       

      字典和数组

      转自:http:///sCQJy

      #!/bin/bash
       
      echo "shell定义字典"
      #必须先声明
      declare -A dic
      dic=([key1]="value1" [key2]="value2" [key3]="value3")
       
      #打印指定key的value
      echo ${dic["key1"]}
      #打印所有key值
      echo ${!dic[*]}
      #打印所有value
      echo ${dic[*]}
       
      #遍历key值
      for key in $(echo ${!dic[*]})
      do
              echo "$key : ${dic[$key]}"
      done
       
      echo "shell定义数组"
       
      #数组
      list=("value1" "value2" "value3")
      #打印指定下标
      echo ${list[1]}
      #打印所有下标
      echo ${!list[*]}
      #打印数组下标
      echo ${list[*]}
      #数组增加一个元素
      list=("${list[@]}" "value3")
      
      版权声明:本文内容来自第三方投稿或授权转载,原文地址:https://blog.csdn.net/bandaoyu/article/details/115484801,作者:bandaoyu,版权归原作者所有。本网站转在其作品的目的在于传递更多信息,不拥有版权,亦不承担相应法律责任。如因作品内容、版权等问题需要同本网站联系,请发邮件至ctyunbbs@chinatelecom.cn沟通。

      上一篇:【C/C++】程序在main之前/之后执行代码|main之前打印编译日期

      下一篇:【C++动态规划 01背包】2787. 将一个数字表示成幂的和的方案数|1817

      相关文章

      2025-04-18 07:10:44

      shell编程-重定向与打印命令详解(超详细)

      重定向可以改变命令的输入和输出位置,使得我们可以将输入从键盘改为文件,将输出从屏幕改为文件。而echo命令和printf命令则用于在Shell中输出文本或变量的值,并可以进行格式化输出。

      2025-04-18 07:10:44
      echo , Shell , 命令 , 文件 , 示例 , 输出 , 重定向
      2025-04-14 09:31:41

      awk实践_进阶知识_逻辑运算

      awk实践_进阶知识_逻辑运算

      2025-04-14 09:31:41
      awk , 基础知识 , 实践
      2025-04-14 09:31:41

      awk实践_进阶知识_赋值运算

      awk实践_进阶知识_赋值运算

      2025-04-14 09:31:41
      awk , 基础知识 , 实践 , 数学 , 运算
      2025-04-14 09:28:41

      awk实践_逻辑控制_for循环

      awk实践_逻辑控制_for循环

      2025-04-14 09:28:41
      awk , 基础知识 , 实践 , 循环
      2025-04-14 09:28:41

      awk实践_逻辑控制_1.3.1 if条件

      awk实践_逻辑控制_1.3.1 if条件

      2025-04-14 09:28:41
      awk , 基础知识 , 实践 , 表达式
      2025-04-11 07:16:37

      awk实践_逻辑控制_switch条件

      awk实践_逻辑控制_switch条件

      2025-04-11 07:16:37
      awk , switch , 基础知识 , 实践 , 简单
      2025-03-21 06:56:59

      【shell】遍历目录及其子目录中的所有文件|判断文件是否有修改

      【shell】遍历目录及其子目录中的所有文件|判断文件是否有修改

      2025-03-21 06:56:59
      date , echo , log , shell , sudo
      2025-03-21 06:56:59

      【shell】echo -n 和echo -e |echo换行/不换行输出|彩色输出

      【shell】echo -n 和echo -e |echo换行/不换行输出|彩色输出

      2025-03-21 06:56:59
      echo , 光标 , 字符 , 换行 , 输出 , 颜色
      2025-03-21 06:56:59

      【shell】Linux 连续执行多条命令的方法和区别

      【shell】Linux 连续执行多条命令的方法和区别

      2025-03-21 06:56:59
      amp , echo , 命令 , 执行
      2025-03-21 06:56:46

      【shell】shell笔记--->特殊符号|编程注意|脚本获本身绝对路径

      【shell】shell笔记--->特殊符号|编程注意|脚本获本身绝对路径

      2025-03-21 06:56:46
      bash , echo , 命令 , 空格
      查看更多
      推荐标签

      作者介绍

      天翼云小翼
      天翼云用户

      文章

      33561

      阅读量

      5275042

      查看更多

      最新文章

      shell编程-重定向与打印命令详解(超详细)

      2025-04-18 07:10:44

      【shell】shell笔记--->特殊符号|编程注意|脚本获本身绝对路径

      2025-03-21 06:56:46

      【ceph】async通信message路径 伪代码

      2025-03-18 08:27:19

      【测试】echo发送和接收TCP/UDP数据包|shell 发送TCP/UDP数据包

      2025-02-26 07:22:00

      【ceph】Messenger的基准测试工具ceph_perf_msgr_server/ceph_perf_msgr_client|性能测试

      2025-02-26 07:21:49

      【ceph】simpleManssager通信代码分析

      2025-02-25 08:55:16

      查看更多

      热门文章

      7、awk编程语言

      2023-03-31 06:14:11

      ceph块设备 VS 本地块设备 使用pgbench TPC-B测试数据对比记录

      2023-07-04 07:09:54

      命令行查看Git提交的代码量(图文)

      2024-12-11 06:20:18

      Awk命令的高级用法与文本处理技巧

      2024-11-14 08:11:40

      Python a bytes-like object is required, not \'str\'

      2024-07-11 09:40:42

      Linux shell编程学习笔记15:定义数组、获取数组元素值和长度

      2024-10-24 07:48:21

      查看更多

      热门标签

      java Java python 编程开发 代码 开发语言 算法 线程 Python html 数组 C++ 元素 javascript c++
      查看更多

      相关产品

      弹性云主机

      随时自助获取、弹性伸缩的云服务器资源

      天翼云电脑(公众版)

      便捷、安全、高效的云电脑服务

      对象存储

      高品质、低成本的云上存储服务

      云硬盘

      为云上计算资源提供持久性块存储

      查看更多

      随机文章

      Linux shell编程学习笔记12:布尔运算和逻辑运算

      Linux shell编程学习笔记21:用select in循环语句打造菜单

      【ceph】async通信message路径 伪代码

      Linux shell编程学习笔记23:[] [[]]的用法小结

      ceph块设备 VS 本地块设备 使用pgbench TPC-B测试数据对比记录

      Linux shell编程学习笔记24:函数定义和使用

      • 7*24小时售后
      • 无忧退款
      • 免费备案
      • 专家服务
      售前咨询热线
      400-810-9889转1
      关注天翼云
      • 旗舰店
      • 天翼云APP
      • 天翼云微信公众号
      服务与支持
      • 备案中心
      • 售前咨询
      • 智能客服
      • 自助服务
      • 工单管理
      • 客户公告
      • 涉诈举报
      账户管理
      • 管理中心
      • 订单管理
      • 余额管理
      • 发票管理
      • 充值汇款
      • 续费管理
      快速入口
      • 天翼云旗舰店
      • 文档中心
      • 最新活动
      • 免费试用
      • 信任中心
      • 天翼云学堂
      云网生态
      • 甄选商城
      • 渠道合作
      • 云市场合作
      了解天翼云
      • 关于天翼云
      • 天翼云APP
      • 服务案例
      • 新闻资讯
      • 联系我们
      热门产品
      • 云电脑
      • 弹性云主机
      • 云电脑政企版
      • 天翼云手机
      • 云数据库
      • 对象存储
      • 云硬盘
      • Web应用防火墙
      • 服务器安全卫士
      • CDN加速
      热门推荐
      • 云服务备份
      • 边缘安全加速平台
      • 全站加速
      • 安全加速
      • 云服务器
      • 云主机
      • 智能边缘云
      • 应用编排服务
      • 微服务引擎
      • 共享流量包
      更多推荐
      • web应用防火墙
      • 密钥管理
      • 等保咨询
      • 安全专区
      • 应用运维管理
      • 云日志服务
      • 文档数据库服务
      • 云搜索服务
      • 数据湖探索
      • 数据仓库服务
      友情链接
      • 中国电信集团
      • 189邮箱
      • 天翼企业云盘
      • 天翼云盘
      ©2025 天翼云科技有限公司版权所有 增值电信业务经营许可证A2.B1.B2-20090001
      公司地址:北京市东城区青龙胡同甲1号、3号2幢2层205-32室
      • 用户协议
      • 隐私政策
      • 个人信息保护
      • 法律声明
      备案 京公网安备11010802043424号 京ICP备 2021034386号