{"id":150837,"date":"2019-07-16T10:19:07","date_gmt":"2019-07-16T02:19:07","guid":{"rendered":"https:\/\/lrxjmw.cn\/?p=150837"},"modified":"2019-07-08T09:20:28","modified_gmt":"2019-07-08T01:20:28","slug":"shell-json-data","status":"publish","type":"post","link":"https:\/\/lrxjmw.cn\/shell-json-data.html","title":{"rendered":"shell\u811a\u672c\u6574\u5408json\u6570\u503c\u8f93\u51fa\u4ece\u800c\u83b7\u53d6\u786c\u4ef6\u4fe1\u606f"},"content":{"rendered":"\n\n\n
\u5bfc\u8bfb<\/td>\n\u67e5\u770b\u786c\u4ef6\u4fe1\u606f\uff0c\u5e76\u5c06\u4fe1\u606f\u6574\u5408\u6210json\u6570\u503c\uff0c\u7136\u540e\u4f20\u7ed9\u524d\u6bb5\u8fdb\u884c\u5206\u6790\uff0c\u6700\u540e\u518d\u8fdb\u884c\u76f8\u5e94\u7684\u5904\u7406\u3002\u5728\u88c5\u7cfb\u7edf\u7684\u65f6\u5019\uff0c\u6216\u662f\u8fdb\u884c\u76d1\u63a7\u65f6\uff0c\u90fd\u662f\u4e00\u4e2a\u6807\u51c6\u7684\u81ea\u52a8\u5316\u8fd0\u7ef4\u6d41\u7a0b\u3002\u4f7f\u7528shell\u76f4\u63a5\u751f\u6210\u597djson\u6570\u636e\u518d\u8fdb\u884c\u4f20\u8f93\uff0c\u4f1a\u53d8\u5f97\u975e\u5e38\u65b9\u4fbf\u3002\u6240\u4ee5\u62bd\u65f6\u95f4\u5199\u4e86\u8fd9\u4e2a\u5c0f\u811a\u672c\uff0c\u4f9b\u5927\u5bb6\u53c2\u8003\uff0c\u91cc\u9762\u8fd8\u6709\u5f88\u591a\u4e0d\u5b8c\u5584\u7684\u5730\u65b9\uff0c\u6709\u5174\u8da3\u7684\u670b\u53cb\u53ef\u4ee5\u81ea\u884c\u66f4\u6539<\/strong><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n
\u73af\u5883<\/strong><\/span><\/div>\n

\u9700\u8981\u5b89\u88c5\u5fc5\u8981\u7684\u8f6f\u4ef6\uff0c\u8fd9\u91cc\u6211\u4e3a\u4e86\u4fdd\u969c\u811a\u672c\u5408\u7406\u7684\u8fdb\u884c\uff0c\u4f7f\u7528\u7684\u662f\u771f\u673a\u73af\u5883\uff0c\u6ca1\u6709\u4f7f\u7528\u865a\u62df\u673a<\/p>\n

\r\n[root@sys-idc-pxe01 ~]# yum install jq lsscsi MegaCli\r\nLoaded plugins: fastestmirror, security\r\nLoading mirror speeds from cached hostfile\r\nSetting up Install Process\r\nPackage jq-1.3-2.el6.x86_64 already installed and latest version\r\nPackage lsscsi-0.23-3.el6.x86_64 already installed and latest version\r\nPackage MegaCli-8.00.40-1.i386 already installed and latest version\r\nNothing to do\r\n<\/pre>\n
\u811a\u672c\u5185\u5bb9<\/strong><\/span><\/div>\n

\u6211\u7684shell\u98ce\u683c\u6bd4\u8f83\u504f\u5411\u6a21\u5757\u5316\uff0c\u6240\u4ee5\u4f7f\u7528\u51fd\u6570\u4f1a\u591a\u4e00\u4e9b\uff0c\u8fd9\u6837\u65b9\u4fbf\u7406\u89e3\uff0c\u76f8\u4fe1\u5927\u5bb6\u4e5f\u80fd\u770b\u5f97\u61c2\u3002<\/p>\n

\u6211\u4e0d\u592a\u559c\u6b22python\u98ce\u683c\u7684\u4ee3\u7801\u683c\u5f0f\uff08\u867d\u7136\u6211python\u5199\u7684\u4e5f\u5f88\u4e0d\u9519\uff09\uff0c\u770b\u8d77\u6765\u7ed9\u4eba\u7684\u611f\u89c9\u592a\u7d27\u51d1\uff0c\u592a\u4e71\u3002\u636e\u8bf4\u662f\u524d\u8f88\u4eec\u51fa\u7248\u4e66\u7c4d\u7684\u65f6\u5019\u4e3a\u4e86\u7701\u7eb8\uff0c\u624d\u51fa\u73b0\u7684\u90a3\u79cd\u98ce\u683c\uff0c\u540e\u8f88\u6000\u7740\u5bf9\u524d\u8f88\u7684\u656c\u4ef0\u5c31\u5ef6\u7eed\u4e86\u4e0b\u6765\uff0c\u5176\u5b9e\u524d\u8f88\u4e5f\u6ca1\u6709\u90a3\u4e48\u5199\u8fc7\u90a3\u79cd\u98ce\u683c\u7684\u4ee3\u7801\uff0c\u4e0d\u77e5\u9053\u662f\u4e0d\u662f\u771f\u7684\u3002<\/p>\n

\r\n[root@sys-idc-pxe01 ~]# cat .\/get_server_info.sh \r\n#!\/bin\/sh\r\n#description: get server hardware info\r\n#author: liuxin\r\n#date: 20180122\r\n#\u9700\u8981\u5b89\u88c5jq\u5de5\u5177 yum install jq\r\n\r\n#\u7528\u4e8e\u5b58\u653e\u8be5\u670d\u52a1\u5668\u7684\u6240\u6709\u4fe1\u606f\uff0c\u4e2a\u4eba\u559c\u6b22\u628a\u5168\u5c40\u53d8\u91cf\u5199\u5230\u5916\u9762\r\n#\u5199\u5230\u51fd\u6570\u91cc\u9762\uff0c\u6ca1\u6709\u52a0local\u7684\u53d8\u91cf\u4e5f\u662f\u5168\u5c40\u53d8\u91cf\r\nINFO=\"{}\"\r\n\r\n#\u5b9a\u4e49\u4e00\u4e2a\u5de5\u5177\u51fd\u6570\uff0c\u7528\u4e8e\u751f\u6210json\u6570\u503c\uff0c\u540e\u9762\u5c06\u4f1a\u9891\u7e41\u7528\u5230\r\nfunction create_json()\r\n{\r\n  #utility function\r\n  local key=$1\r\n  local value=\"$2\"\r\n  local json=\"\"\r\n\r\n  #if value is string\r\n  if [ -z \"$(echo \"$value\" |egrep \"\\[|\\]|\\{|\\}\")\" ]\r\n  then\r\n    json=$(jq -n {\"$key\":\"\\\"$value\\\"\"})\r\n  #if value is json, object\r\n  elif [ \"$(echo \"$value\" |jq -r type)\" == \"object\" ]\r\n  then\r\n    json=$(jq -n {\"$key\":\"$value\"})\r\n  #if value is array\r\n  elif [ \"$(echo \"$value\" |jq -r type)\" == \"array\" ]\r\n  then\r\n    json=$(jq -n \"{$key:$value}\")\r\n  else\r\n    echo \"value type error...\"\r\n    exit 1\r\n    return 0\r\n  fi\r\n  echo $json\r\n  return 0\r\n}\r\n\r\n#\u83b7\u53d6CPU\u4fe1\u606f\r\nfunction get_cpu()\r\n{\r\n  #\u83b7\u53d6cpu\u4fe1\u606f\uff0c\u53bb\u6389\u7a7a\u683c\u548c\u5236\u8868\u7b26\u548c\u7a7a\u884c\uff0c\u4ee5\u4fbf\u4e8efor\u5faa\u73af\r\n  local cpu_model_1=$(dmidecode -s processor-version |grep '@' |tr -d \" \" |tr -s \"\\n\" |tr -d \"\\t\")\r\n  local cpu_info=\"{}\"\r\n  local i=0\r\n\r\n  #\u56e0\u4e3a\u53bb\u6389\u4e86\u7a7a\u683c\u548c\u5236\u8868\u7b26\uff0c\u4ee5\u4e0b\u9ed8\u8ba4\u4f7f\u7528\u6362\u884c\u7b26\u5206\u9694\r\n  for line in $(echo \"$cpu_model_1\")\r\n  do\r\n    local cpu_model=\"$line\"\r\n    local cpu1=$(create_json \"cpu_model\" \"$cpu_model\")\r\n    #\u83b7\u53d6\u6bcf\u5757cpu\u7684\u4fe1\u606f\uff0c\u8fd9\u91cc\u53ea\u8bb0\u5f55\u4e86\u578b\u53f7\r\n    local cpu=$(create_json \"cpu_$i\" \"$cpu1\")\r\n    local cpu_info=$(jq -n \"$cpu_info + $cpu\")\r\n    i=$[ $i + 1]\r\n  done\r\n\r\n  #\u5c06cpu\u7684\u4fe1\u606f\u6574\u5408\u6210\u4e00\u4e2ajson\uff0ckey\u662fcpu\r\n  local info=$(create_json \"cpu\" \"$cpu_info\")\r\n  #\u5c06\u4fe1\u606f\u52a0\u5165\u5230\u5168\u5c40\u53d8\u91cf\u4e2d\r\n  INFO=$(jq -n \"$INFO + $info\")\r\n\r\n  return 0\r\n}\r\n\r\nfunction get_mem()\r\n{\r\n\r\n  #generate json {Locator:{sn:sn,size:size}}\r\n  local mem_info=\"{}\"\r\n  #\u83b7\u53d6\u6bcf\u4e2a\u5185\u5b58\u7684\u4fe1\u606f\uff0c\u5305\u62ecSize:|Locator:|Serial Number:\r\n  local mem_info_1=$(dmidecode -t memory |egrep 'Size:|Locator:|Serial Number:' |grep -v 'Bank Locator:' |awk '\r\n  {\r\n    if (NR%3==1 && $NF==\"MB\")\r\n    {\r\n      size=$2;\r\n      getline (NR+1);\r\n      locator=$2;\r\n      getline (NR+2);\r\n      sn=$NF;\r\n      printf(\"%s,%s,%s\\n\",locator,size,sn)\r\n    }\r\n  }')\r\n\r\n  #\u6839\u636e\u4e0a\u9762\u7684\u4fe1\u606f\uff0c\u5c06\u4fe1\u606f\u8fc7\u6ee4\u5e76\u6574\u5408\u6210json\r\n  local i=0\r\n  for line in $(echo \"$mem_info_1\")\r\n  do\r\n    local locator=$(echo $line |awk -F , '{print $1}')\r\n    local      sn=$(echo $line |awk  -F , '{print $3}')\r\n    local    size=$(echo $line |awk -F , '{print $2}')\r\n\r\n    local mem1=$(create_json \"locator\" \"$locator\")\r\n    local mem2=$(create_json \"sn\" \"$sn\")\r\n    local mem3=$(create_json \"size\" \"$size\")\r\n    local mem4=$(jq -n \"$mem1 + $mem2 + $mem3\")\r\n    #\u6bcf\u6761\u5185\u5b58\u7684\u4fe1\u606f\uff0ckey\u662f\u5185\u5b58\u4ece0\u5f00\u59cb\u7684\u5e8f\u53f7\r\n    local mem=$(create_json \"mem_$i\" \"$mem4\")\r\n    #\u5c06\u8fd9\u4e9b\u5185\u5b58\u7684\u4fe1\u606f\u7ec4\u5408\u5230\u4e00\u4e2ajson\u4e2d\r\n    mem_info=$(jq -n \"$mem_info + $mem\")\r\n    i=$[ $i + 1 ]\r\n  done\r\n\r\n  #\u7ed9\u8fd9\u4e9b\u5185\u5b58\u7684\u4fe1\u606f\u8bbe\u7f6ekey\uff0cmem\r\n  local info=$(create_json \"mem\" \"$mem_info\")\r\n  INFO=$(jq -n \"$INFO + $info\")\r\n\r\n  return 0\r\n}\r\n\r\nfunction get_megacli_disk()\r\n{\r\n  #\u8bbe\u7f6emegacli\u5de5\u5177\u7684\u8def\u5f84\uff0c\u6b64\u6761\u53ef\u4ee5\u6839\u636e\u60c5\u51b5\u66f4\u6539\r\n  local raid_tool=\"\/opt\/MegaRAID\/MegaCli\/MegaCli64\"\r\n  #\u5c06\u786c\u76d8\u4fe1\u606f\u83b7\u53d6\uff0c\u4fdd\u5b58\u4e0b\u6765\uff0c\u7701\u53bb\u6bcf\u6b21\u90fd\u6267\u884c\u7684\u64cd\u4f5c\r\n  $raid_tool pdlist aall >\/tmp\/megacli_pdlist.txt\r\n\r\n  local disk_info=\"{}\"\r\n  #\u83b7\u53d6\u786c\u76d8\u7684\u5fc5\u8981\u4fe1\u606f\r\n  local disk_info_1=$(cat \/tmp\/megacli_pdlist.txt |egrep 'Enclosure Device ID:|Slot Number:|PD Type:|Raw Size:|Inquiry Data:|Media Type:'|awk '\r\n{\r\n  if(NR%6==1 && $1$2==\"EnclosureDevice\")\r\n  {\r\n    E=$NF;\r\n    getline (NR+1);\r\n    S=$NF;\r\n    getline (NR+2);\r\n    pdtype=$NF;\r\n    getline (NR+3);\r\n    size=$3$4;\r\n    getline (NR+4);\r\n    sn=$3$4$5$6;\r\n    getline (NR+5);\r\n    mediatype=$3$4$5$6;\r\n    printf(\"%s,%s,%s,%s,%s,%s\\n\",E,S,pdtype,size,sn,mediatype)\r\n  }\r\n}')\r\n\r\n  #\u5c06\u83b7\u53d6\u5230\u7684\u786c\u76d8\u4fe1\u606f\u8fdb\u884c\u6574\u5408\uff0c\u751f\u6210json\r\n  local i=0\r\n  for line in $(echo $disk_info_1)\r\n  do\r\n    #local       key=$(echo $line |awk -F , '{printf(\"ES%s_%s\\n\",$1,$2)}')\r\n    local         E=$(echo $line |awk -F , '{print $1}')\r\n    local         S=$(echo $line |awk -F , '{print $2}')\r\n    local    pdtype=$(echo $line |awk -F , '{print $3}')\r\n    local      size=$(echo $line |awk -F , '{print $4}')\r\n    local        sn=$(echo $line |awk -F , '{print $5}')\r\n    local mediatype=$(echo $line |awk -F , '{print $6}')\r\n\r\n    local disk1=$(create_json \"pdtype\" \"$pdtype\")\r\n    local disk1_1=$(create_json \"enclosure_id\" \"$E\")\r\n    local disk1_2=$(create_json \"slot_id\" \"$S\")\r\n    local disk2=$(create_json \"size\" \"$size\")\r\n    local disk3=$(create_json \"sn\" \"$sn\")\r\n    local disk4=$(create_json \"mediatype\" \"$mediatype\")\r\n    local disk5=$(jq -n \"$disk1 + $disk1_1 + $disk1_2 + $disk2 + $disk3 + $disk4\")\r\n    local disk=$(create_json \"disk_$i\" \"$disk5\")\r\n    disk_info=$(jq -n \"$disk_info + $disk\")\r\n    i=$[ $i + 1 ]\r\n  done\r\n  #echo $disk_info\r\n  local info=$(create_json \"disk\" \"$disk_info\")\r\n  INFO=$(jq -n \"$INFO + $info\")\r\n\r\n  return 0\r\n}\r\n\r\nfunction get_hba_disk()\r\n{\r\n  #\u5bf9\u4e8ehba\u5361\u7684\u786c\u76d8\uff0c\u4f7f\u7528smartctl\u83b7\u53d6\u786c\u76d8\u4fe1\u606f\r\n  local disk_tool=\"smartctl\"\r\n  local disk_info=\"{}\"\r\n  #lsscsi \u9700\u8981\u4f7f\u7528yum install lsscsi \u5b89\u88c5\r\n  local disk_info_1=$(lsscsi -g |grep -v 'enclosu' |awk '{printf(\"%s,%s,%s,%s\\n\",$1,$2,$(NF-1),$NF)}')\r\n  local i=0\r\n  for line in $(echo $disk_info_1)\r\n  do\r\n    local         E=$(echo $line |awk -F , '{print $1}' |awk -F ':' '{print $1}' |tr -d '\\[|\\]')\r\n    local         S=$(echo $line |awk -F , '{print $NF}' |egrep -o [0-9]*)\r\n    local        sd=$(echo $line |awk -F , '{print $(NF-1)}')\r\n    $disk_tool -i $sd >\/tmp\/disk_info.txt\r\n    local    pdtype=\"SATA\"\r\n    if [ \"$(cat \/tmp\/disk_info.txt |grep 'Transport protocol:' |awk '{print $NF}')\" == \"SAS\" ]\r\n    then\r\n    local    pdtype=\"SAS\"\r\n    fi\r\n    local      size=$(cat \/tmp\/disk_info.txt |grep 'User Capacity:' |awk '{printf(\"%s%s\\n\",$(NF-1),$NF)}' |tr -d '\\[|\\]')\r\n    local        sn=$(cat \/tmp\/disk_info.txt |grep 'Serial Number:' |awk '{print $NF}')\r\n    local mediatype=\"disk\"\r\n\r\n    local disk1=$(create_json \"pdtype\" \"$pdtype\")\r\n    local disk1_1=$(create_json \"enclosure_id\" \"$E\")\r\n    local disk1_2=$(create_json \"slot_id\" \"$S\")\r\n    local disk2=$(create_json \"size\" \"$size\")\r\n    local disk3=$(create_json \"sn\" \"$sn\")\r\n    local disk4=$(create_json \"mediatype\" \"$mediatype\")\r\n    local disk5=$(jq -n \"$disk1 + $disk1_1 + $disk1_2 + $disk2 + $disk3 + $disk4\")\r\n    local disk=$(create_json \"disk_$i\" \"$disk5\")\r\n    disk_info=$(jq -n \"$disk_info + $disk\")\r\n    i=$[ $i + 1 ]\r\n  done\r\n  #echo $disk_info\r\n  local info=$(create_json \"disk\" \"$disk_info\")\r\n  INFO=$(jq -n \"$INFO + $info\")\r\n\r\n  return 0\r\n}\r\n\r\nfunction get_disk()\r\n{\r\n  #\u6839\u636e\u83b7\u53d6\u5230\u7684\u786c\u76d8\u63a7\u5236\u5668\u7c7b\u578b\uff0c\u6765\u5224\u65ad\u4f7f\u7528\u4ec0\u4e48\u5de5\u5177\u91c7\u96c6\u786c\u76d8\u4fe1\u606f\r\n  if [ \"$(echo \"$INFO\" |jq -r .disk_ctrl.disk_ctrl_0.type)\" == \"raid\" ]\r\n  then\r\n    get_megacli_disk\r\n  elif [ \"$(echo \"$INFO\" |jq -r .disk_ctrl.disk_ctrl_0.type)\" == \"hba\" ]\r\n  then\r\n    get_hba_disk\r\n  else\r\n    local info=$(create_json \"disk\" \"error\")\r\n    INFO=$(jq -n \"$INFO + $info\")\r\n  fi\r\n  #hp\u673a\u5668\u6bd4\u8f83\u7279\u6b8a\uff0c\u8fd9\u91cc\u6211\u6ca1\u6709\u505ahp\u673a\u5668\u786c\u76d8\u4fe1\u606f\u91c7\u96c6\uff0c\u6709\u5174\u8da3\u7684\u670b\u53cb\u53ef\u4ee5\u81ea\u884c\u6dfb\u52a0\u4e0a\r\n  #if hp machine\r\n\r\n  return 0\r\n}\r\n\r\nfunction get_diskController()\r\n{\r\n  local disk_ctrl=\"{}\"\r\n  #if LSI Controller\r\n  local disk_ctrl_1=\"$(lspci -nn |grep LSI)\"\r\n  local i=0\r\n  \r\n  #\u4ee5\u6362\u884c\u7b26\u5206\u9694\r\n  IFS_OLD=$IFS && IFS=$'\\n'\r\n  for line in $(echo \"$disk_ctrl_1\")\r\n  do\r\n    #echo $line\r\n    local   ctrl_id=$(echo \"$line\" |awk -F ']:' '{print $1}' |awk '{print $NF}' |tr -d '\\[|\\]')\r\n\r\n    case \"$ctrl_id\" in\r\n    #\u6839\u636e\u63a7\u5236\u5668\u7684id\u6216\u8fdb\u884c\u5224\u65ad\u662fraid\u5361\u8fd8\u662fhba\u5361\uff0c\u56e0\u4e3a\u54c1\u724c\u6bd4\u8f83\u591a\uff0c\u540e\u7eed\u53ef\u4ee5\u5728\u6b64\u5904\u8fdb\u884c\u6269\u5c55\u6dfb\u52a0\r\n    0104)\r\n      # \u83b7\u53d6Logic\u4ee5\u540e\u7684\u5b57\u7b26\u4e32\uff0c\u5e76\u8fdb\u884c\u62fc\u63a5\r\n      local ctrl_name=$(echo \"${line##*\"Logic\"}\" |awk '{printf(\"%s_%s_%s\\n\",$1,$2,$3)}')\r\n      local     ctrl1=$(create_json \"id\" \"$ctrl_id\")\r\n      local     ctrl2=$(create_json \"type\" \"raid\")\r\n      local     ctrl3=$(create_json \"name\" \"$ctrl_name\")\r\n      ;;\r\n    0100|0107)\r\n      local ctrl_name=$(echo \"${line##*\"Logic\"}\" |awk '{printf(\"%s_%s_%s\\n\",$1,$3,$4)}')\r\n      local     ctrl1=$(create_json \"id\" \"$ctrl_id\")\r\n      local     ctrl2=$(create_json \"type\" \"hba\")\r\n      local     ctrl3=$(create_json \"name\" \"$ctrl_name\")\r\n      ;;\r\n    *)\r\n      local     ctrl1=$(create_json \"id\" \"----\")\r\n      local     ctrl2=$(create_json \"type\" \"----\")\r\n      local     ctrl3=$(create_json \"name\" \"----\")\r\n      ;;\r\n    esac\r\n    local ctrl_tmp=$(jq -n \"$ctrl1 + $ctrl2 + $ctrl3\")\r\n    local ctrl=$(create_json \"disk_ctrl_$i\" \"$ctrl_tmp\")\r\n    disk_ctrl=$(jq -n \"$disk_ctrl + $ctrl\")\r\n    i=$[ $i + 1 ]\r\n  done\r\n  IFS=$IFS_OLD\r\n  local info=$(create_json \"disk_ctrl\" \"$disk_ctrl\")\r\n  INFO=$(jq -n \"$INFO + $info\")\r\n\r\n  return 0\r\n}\r\n\r\nfunction get_netcard()\r\n{\r\n  local netcard_info=\"{}\"\r\n  local netcard_info_1=\"$(lspci -nn |grep Ether)\"\r\n  local i=0\r\n  #echo \"$netcard_info_1\"\r\n  IFS_OLD=$IFS && IFS=$'\\n'\r\n  for line in $(echo \"$netcard_info_1\")\r\n  do\r\n    local     net_id=$(echo $line |egrep -o '[0-9a-z]{4}:[0-9a-z]{4}')\r\n    local   net_id_1=$(echo $net_id |awk -F : '{print $1}')\r\n\r\n    case \"$net_id_1\" in\r\n    8086)\r\n      local net_name=$(echo \"${line##*\": \"}\" |awk '{printf(\"%s_%s_%s_%s\\n\",$1,$3,$4,$5)}')\r\n      local     type=$(echo $line |egrep -o SFP || echo \"TP\")\r\n      local     net1=$(create_json \"id\" \"$net_id\")\r\n      local     net2=$(create_json \"name\" \"$net_name\")\r\n      local     net3=$(create_json \"type\" \"$type\")\r\n      ;;\r\n    14e4)\r\n      local net_name=$(echo \"${line##*\": \"}\" |awk '{printf(\"%s_%s_%s_%s\\n\",$1,$3,$4,$5)}')\r\n      local     type=$(echo $line |egrep -o SFP || echo \"TP\")\r\n      local     net1=$(create_json \"id\" \"$net_id\")\r\n      local     net2=$(create_json \"name\" \"$net_name\")\r\n      local     net3=$(create_json \"type\" \"$type\")\r\n      ;;\r\n    *)\r\n      local net_name=$(echo \"${line##*\": \"}\" |awk '{printf(\"%s_%s_%s_%s\\n\",$1,$3,$4,$5)}')\r\n      local     type=$(echo $line |egrep -o SFP || echo \"TP\")\r\n      local     net1=$(create_json \"id\" \"$net_id\")\r\n      local     net2=$(create_json \"name\" \"$net_name\")\r\n      local     net3=$(create_json \"type\" \"$type\")\r\n      ;;\r\n    esac\r\n\r\n    local net1=$(jq -n \"$net1 + $net2 + $net3\")\r\n    #echo $net\r\n    local net2=$(create_json \"net_$i\" \"$net1\")\r\n    netcard_info=$(jq -n \"$netcard_info + $net2\")\r\n    i=$[ $i + 1 ]\r\n\r\n  done\r\n  IFS=$IFS_OLD\r\n  local info=$(create_json \"net\" \"$netcard_info\")\r\n  INFO=$(jq -n \"$INFO + $info\")\r\n\r\n  return 0\r\n}\r\n\r\nfunction get_server()\r\n{\r\n  local product=$(dmidecode -s system-product-name |grep -v '^#' |tr -d ' ' |head -n1)\r\n  local manufacturer=$(dmidecode -s system-manufacturer |grep -v '^#' |tr -d ' ' |head -n1)\r\n  local server1=$(create_json \"manufacturer\" \"$manufacturer\")\r\n  local server2=$(create_json \"product\" \"$product\")\r\n  local server3=$(jq -n \"$server1 + $server2\")\r\n  local info=$(create_json \"basic_info\" \"$server3\")\r\n  INFO=$(jq -n \"$INFO + $info\")\r\n\r\n  return 0\r\n}\r\n\r\nALL_INFO=\"\"\r\nfunction get_all()\r\n{\r\n  #\u56e0\u4e3a\u786c\u76d8\u4fe1\u606f\u7684\u83b7\u53d6\u4f9d\u8d56\u786c\u76d8\u63a7\u5236\u5668\u7684\u4fe1\u606f\uff0c\u6240\u4ee5get_diskController\u8981\u653e\u5230get_disk\u524d\u9762\r\n  get_server\r\n  get_cpu\r\n  get_mem\r\n  get_diskController\r\n  get_disk\r\n  get_netcard\r\n\r\n  local sn=$(dmidecode -s system-serial-number |grep -v '^#' |tr -d ' ' |head -n1)\r\n  ALL_INFO=$(create_json \"$sn\" \"$INFO\")\r\n  return 0\r\n}\r\n\r\nfunction main()\r\n{\r\n  get_all\r\n  echo $ALL_INFO\r\n  return 0\r\n}\r\n\r\n#-------------------------------------------------\r\nmain\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"

\u9700\u8981\u5b89\u88c5\u5fc5\u8981\u7684\u8f6f\u4ef6\uff0c\u8fd9\u91cc\u6211\u4e3a\u4e86\u4fdd\u969c\u811a\u672c\u5408\u7406\u7684\u8fdb\u884c\uff0c\u4f7f\u7528\u7684\u662f\u771f\u673a\u73af\u5883\uff0c\u6ca1\u6709\u4f7f\u7528\u865a\u62df\u673a [root@sys-idc […]<\/p>\n","protected":false},"author":1479,"featured_media":116344,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[55],"tags":[],"class_list":["post-150837","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-thread"],"acf":[],"_links":{"self":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/150837","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/users\/1479"}],"replies":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/comments?post=150837"}],"version-history":[{"count":4,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/150837\/revisions"}],"predecessor-version":[{"id":150941,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/150837\/revisions\/150941"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media\/116344"}],"wp:attachment":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media?parent=150837"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/categories?post=150837"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/tags?post=150837"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}