【Linux】Linux作業系統檢視伺服器配置資訊
阿新 • • 發佈:2018-12-13
檢視伺服器配置資訊
編寫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,結果如下