【Linux】Linux操作系统查看服务器配置信息

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/ARPOSPF/article/details/84835972

查看服务器配置信息


编写bash shell脚本查看Linux操作系统的服务器配置信息

  1 #!/bin/bash
  2 echo "This lists the information of this computer."
  3 echo
  4 echo "Hostname is $(tput setaf 3)`hostname`$(tput sgr0),\
  5 Ip address is $(tput setaf 3)\
  6 `/sbin/ifconfig | sed -n '2p' | cut -d ':' -f 2 | cut -d ' ' -f 1`.
  7 $(tput sgr0)"
  8 
  9 nuclear=`uname -a | cut -d ' ' -f 3`
 10 bitInfo=`uname -a | cut -d ' ' -f 12`
 11 
 12 if test $bitInfo == "x86_64"; then
 13         bit=64
 14 else
 15         bit=32
 16 fi
 17 echo "The $(tput bold)${bit}$(tput sgr0) bit operating system is $(tput bold) `head -n 1 /etc/issue`$(tput sgr0), Nuclear info is $(tput setaf 1)${nuclear}$(tput sgr0)."
 18 echo
 19 echo "The CPU is$(tput setaf 4)`sed -n '5p' /proc/cpuinfo | cut -d ':' -f 2 | sed 's/[ ] */ /g'`$(tput sgr0)."
 20 echo
 21 echo "There are $(tput setaf 5)`cat /proc/cpuinfo | grep "physical id" | sort | uniq | wc -l`$(tput sgr0) physical cpu, each physical cpu has$(tput setaf 5)`sed -n '12p' /proc/c    puinfo | cut -d ':' -f 2`$(tput sgr0) cores,$(tput setaf 5)`sed -n '10p' /proc/cpuinfo | cut -d ':' -f 2`$(tput sgr0) threads."
 22 echo
 23 echo "There are $(tput setaf 5)`cat /proc/cpuinfo | grep "cpu cores" | wc -l`$(tput sgr0) logical cpu."
 24 mem=`head -n 1 /proc/meminfo | cut -d ':' -f 2 | sed 's/^ *//g' | cut -d ' ' -f 1`
 25 memInM=$(echo "$mem/1024/1024" | bc -l)
 26 echo
 27 echo "The memory of this server is $(tput setaf 5)${memInM}$(tput sgr0)G."
 28 echo
 29 echo "The disk information is :"
 30 echo "`df -h`"

执行bash filename,结果如下

猜你喜欢

转载自blog.csdn.net/ARPOSPF/article/details/84835972