Using shell scripts to check server hardware information

Source: Internet
Author: User
Tags egrep dell openmanage

1, in order to facilitate the query server hardware information, will need to query the content into the shell footsteps, output their desired format. In fact, it is through the dmidecode command output, and then through the sed,awk,cut command processing.

2, this footstep applies to the HP DL series of servers, the Dell PowerEdge series will have a little content different, so there will be a small tabloid error in the crawl process.

3. The steps are as follows:

#!/bin/bash############################################################################# check the  server hardware configuration## History: 2016/04/16 zhuwei First  Release############################################################################ # set a  safe path before doing anything elsePATH=/sbin:/usr/sbin:/bin:/usr/bin;  Export path # this script must be executed as rootruid= '/usr/bin/ id|awk -f\ (  ' {print $1} ' |awk -f\= ' {print $2} ' #  #OR # ruid= ' id |  Cut -d\ ( -F1 | CUT -D\= -F2 '   #OR #root_uid=0if [ ${ruid} !=   "0"  ];then    echo "This script must be executed as"  root "    exit 1fi # Display an error and  Exiterrorexit ()  {  &NBSp; echo "[email protected]"  >&2    exit 1} # display  the normal printdisplay ()  {    echo -e "\033[32m***************** \033[0m "    echo  -e "\033[32m*\033[0m" [email protected] "    ECHO -E" \033[32m*************** \033[0m "}  #Check  the  Server model, serial numbermodel ()  {    dmidecode|grep  "System  information " -a9|egrep" manufacturer| Product| Serial "     | awk  ' begin {fs=" \ n "; Rs= ""} {print $1,$2,$3} '  | sed  ' s/^[\t]//g '} #Query  cpu informationcpu () {     dmidecode| grep -A55  "Processor information"  |     egrep  "Version:|core count:|thread count:" |sed -e  ' s/^[\t]//'       -e '/version:/i\\ '  | sed  ' 1d '  | awk  ' begin {fs= ' \ n '; Rs= "" "}{print $1,$2," \ T "$ $} '     | sed ' s/version://'} #Query  memory  Informationmemory () {    dmidecode| grep -a12  "Memory Device" |egrep   "type:|size| Speed:|locator:p "     | sed -n -e  '/mb/,/mhz/p '  | sed   '/size:/i\\ '  | sed -e  ' 1d '  -e  ' s/^[\t]*//'      |  awk ' begin {fs= ' \ n '; rs= ""} {print $2} {print "\ T" $ $, "\ T" $, "\ T" $4} '      #sed '/size:/i\\ '  |  sed -e  ' 1d '  -e  ' s/^[\t]*//'   #replaced #     #awk ' begin { Fs= "\ n"}{if (nr%4==1) {print  "\ n"}{print $1}} '  | sed ' s/^[\t]*//'} #Query network informationnetwork () {    i=0    count= ' Dmidecode  | grep -A4  "Bios nic" |sed -e  ' 1d '  | wc -l '      if [ -f  "/tmp/speed.txt"  ];then       rm  -rf /tmp/speed.txt    fi    while [[${i} -lt  ${count} ]]    do      ethtool eth "${i}" | grep  "Speed:"  >> /tmp/speed.txt      let  "i++"      done    dmidecode| grep -A4  "Bios nic" |sed -e   ' 1d '  -e  ' s/^[\t]//' | cut -d, -f2 |     awk    ' fnr==0 {print  \ r \ n '  FILENAME}{print et NR-1  ' \ t '  $0} '       et= "ETH"  > /tmp/network.txt    paste /tmp/network.txt /tmp/speed.txt} display   "system information:"  && model | |  errorExit  "this command is error!" display  "cpu information:"  && cpu| |  errorExit  "this command is error!" display  "memory information:"  && memory | |  errorExit  "this command is error!" display  "network information:"  && network | |  errorExit  "this command is error!"

4, here only for server manufacturers, memory, CPU configuration and network card information, for hard disk information can be based on different manufacturers of management tools to obtain. HP uses the HP-HEALTH-*RPM,G9 version above using hpssacli-*.rpm, which is used after installation: Hpacucli Ctrl all show config to view raid information. Dell installs the Dell OpenManage Server Administrator Tool view, which is viewed by command: Omreport storage Pdisk controller=0.

5. Viewing RAID information can also be viewed using the MEGACLI Open Source Tool, which is not described here.



This article from the "Language tacit" blog, reproduced please contact the author!

Using shell scripts to check server hardware information

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.