Script written by shell to detect hardware information in linux

Source: Internet
Author: User

I previously wrote a script for detecting windonws hardware information in python. Here is a linux system hardware information detection script written using shell a long time ago. You can check it against it. The detection content is basically the same: operating system information, memory, CPU, hard disk partition and mounting, Nic configuration, installed software information, etc.

 
 
  1. #!/bin/bash 
  2. #This script is used to check the server 
  3. #system info 
  4. system_info() { 
  5. echo "**********************************************" 
  6. echo "system info:" 
  7. echo 
  8. echo "   System-release : `cat /etc/redhat-release`" 
  9. echo "   Kernel-release : `uname -a|awk '{print $1,$3}'`" 
  10. echo "   Server-Model : `dmidecode | grep "Product Name:"|sed -n '1p'|awk -F': ' '{print $2}'`" 
  11. echo 
  12.  
  13.  
  14.  
  15.  
  16. #CPU info 
  17. cpu_info() { 
  18. echo "**********************************************" 
  19. echo "CPU info:" 
  20. echo 
  21. echo "    Frequency : `cat /proc/cpuinfo | grep "model name" | uniq |awk -F': ' '{print $2}'`" 
  22. echo "    CPU cores:  `cat /proc/cpuinfo | grep "cpu cores" | uniq |awk -F': ' '{print $2}'`" 
  23. echo "    Logic Count : `cat /proc/cpuinfo | grep "processor" | sort -u| wc -l `" 
  24. echo "    Physical Count : `cat /proc/cpuinfo | grep "physical" | sort -u| wc -l`" 
  25. echo "    Cache size : `cat /proc/cpuinfo| grep "cache size"|uniq|awk '{print $4,$5}'`" 
  26. echo 
  27.  
  28.  
  29.  
  30.  
  31.  
  32. #memory info 
  33. mem_info() { 
  34. memory=`dmidecode |grep "Range Size"|head -1|awk '{print $3$4}'` 
  35. mem_size=`echo "This server has ${memory} memory."` 
  36.  
  37. echo "**********************************************" 
  38. echo "Memory info:" 
  39. echo 
  40. echo "   Total : ${mem_size}" 
  41. echo "   Count : `dmidecode |grep -A16 "Memory Device$"|grep Size|awk '{if($2!~/No/) print $0}'|wc -l`" 
  42. dmidecode |grep -A20 "Memory Device$"|grep Size|sed '{s/^       */   /g};{/No/d}' 
  43. echo 
  44.  
  45.  
  46.  
  47.  
  48.  
  49. #disk and partitions 
  50. swap_pos=`cat /proc/swaps|sed -n '2p'|awk '{print $1}'` 
  51. partition_info() { 
  52. echo "**********************************************" 
  53. echo "Hard disk info:" 
  54. echo 
  55. echo "`fdisk -l|grep Disk|awk -F, '{print $1}'`" 
  56. echo "**********************************************" 
  57. echo "Partition info:" 
  58. echo 
  59. df -h | grep -v Filesystem | sed "s:none:${swap_pos}:" 
  60. echo 
  61.  
  62.  
  63. #network adapter info 
  64. adapter_info() { 
  65.  
  66. duplex_eth0=`ethtool eth0 | grep Duplex | awk '{if($2~/Full/) print "Full"};{if($2~/Half/)print "Half"};{if($2~/Uknown!/) print "unknown"}'` 
  67.  
  68. duplex_eth1=`ethtool eth1 | grep Duplex | awk '{if($2~/Full/) print "Full"};{if($2~/Half/)print "Half"};{if($2~/Uknown!/) print "unknown"}'` 
  69.  
  70. Negotiation_eth0=`ethtool eth0 | grep "Advertised auto-negotiation"|awk -F': ' '{if($2~/No/) print "Non-negotiation."};{if($2~/Yes/) print "Negotiation"}'` 
  71.  
  72. Negotiation_eth1=`ethtool eth1 | grep "Advertised auto-negotiation"|awk -F': ' '{if($2~/No/) print "Non-negotiation"};{if($2~/Yes/) print "Negotiation"}'` 
  73.  
  74. IP_eth0=`cat /etc/sysconfig/network-scripts/ifcfg-eth0|grep IPADDR|awk -F= '{print $2}'` 
  75.  
  76. IP_eth1=`cat /etc/sysconfig/network-scripts/ifcfg-eth1|grep IPADDR|awk -F= '{print $2}'` 
  77.  
  78. speed_eth0=`ethtool eth0|grep Speed|awk '{print $2}'` 
  79. speed_eth1=`ethtool eth1|grep Speed|awk '{print $2}'` 
  80.  
  81. echo "**********************************************" 
  82. echo "Network adapter info:" 
  83. echo  
  84. echo "  IP_eth0 : ${IP_eth0}        IP_eth0 : ${IP_eth1}" 
  85. echo "  Speed_eth0 : ${speed_eth0}          Speed_eth1 : ${speed_eth1}" 
  86. echo "  Duplex_eth0 : ${duplex_eth0}            Duplex_eth1 : ${duplex_eth1}" 
  87. echo "  Negotiation_eth0 : ${Negotiation_eth0}  Negotiation_eth1 : ${Negotiation_eth1}" 
  88. echo 
  89.  
  90.  
  91.  
  92.  
  93. #software package 
  94. software_info() { 
  95. echo "**********************************************" 
  96. echo "SELinux is `cat /etc/selinux/config |grep SELINUX=disabled|awk -F= '{print $2}'||echo "enabled"`" 
  97. echo "`service iptables status|sed 's/Firewall/Iptables/g'`" 
  98. echo 
  99. echo "**********************************************" 
  100. sed -n '/%packages/,/%post/p;' /root/anaconda-ks.cfg|sed '/%post/d;/^$/d' 
  101. echo "**********************************************" 
  102.  
  103.  
  104.  
  105. #del mac-addr 
  106. #sed -i '/HWADDR/d' /etc/sysconfig/network-scripts/ifcfg-eth0 
  107. #sed -i '/HWADDR/d' /etc/sysconfig/network-scripts/ifcfg-eth1 
  108.  
  109.  
  110. system_info 
  111. cpu_info 
  112. mem_info 
  113. partition_info 
  114. adapter_info 
  115. software_info 

 

This article from the "Wang Wei" blog, please be sure to keep this source http://wangwei007.blog.51cto.com/68019/1033808

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.