推薦一個擷取Linux伺服器(ubuntu、centos已測試)資訊的Shell指令碼

來源:互聯網
上載者:User

此指令碼已經在ubuntu以及centos版本上測試通過,直接上原始碼比較爽:

 代碼如下 複製代碼
#!/bin/bash

Line='==========='

#linux發行版名稱
if [[ -f /usr/bin/lsb_release ]]; then
OS=$(/usr/bin/lsb_release -a |grep Description |awk -F : '{print $2}' |sed 's/^[ t]*//g')
else
OS=$(cat /etc/issue |sed -n '1p')
fi

echo -e "${Line}nOS:n${OS}n${Line}"

######################################################################################################

#查看系統是否為64位:uname -m,若出現x86_64,則為64位
OS_version=$(uname -m)
echo -e "OS_version:n${OS_version}n${Line}"


#系統核心版本
kernel_version=$(uname -r)
echo -e "Kernel_version:n${kernel_version}n${Line}"

#cpu型號
CPU=$(grep 'model name' /proc/cpuinfo |uniq |awk -F : '{print $2}' |sed 's/^[ t]*//g' |sed 's/ +/ /g')
echo -e "CPU model:n${CPU}n${Line}"

#物理cpu個數
Counts=$(grep 'physical id' /proc/cpuinfo |sort |uniq |wc -l)
echo -e "Total of physical CPU:n${Counts}n${Line}"

#物理cpu核心數
Cores=$(grep 'cpu cores' /proc/cpuinfo |uniq |awk -F : '{print $2}' |sed 's/^[ t]*//g')
echo -e "Number of CPU coresn${Cores}n${Line}"

#邏輯cpu個數
PROCESSOR=$(grep 'processor' /proc/cpuinfo |sort |uniq |wc -l)
echo -e "Number of logical CPUs:n${PROCESSOR}n${Line}"

#查看CPU當前運行模式是64位還是32位
Mode=$(getconf LONG_BIT)
echo -e "Present Mode Of CPU:n${Mode}n${Line}"


#查看CPU是否支援64位技術:grep 'flags' /proc/cpuinfo,若flags資訊中包含lm欄位,則支援64位
Numbers=$(grep 'lm' /proc/cpuinfo |wc -l)
if (( ${Numbers} > 0)); then lm=64
else lm=32
fi
echo -e "Support Mode Of CPU:n${lm}n${Line}"
######################################################################

#Memtotal 記憶體總大小
Total=$(cat /proc/meminfo |grep 'MemTotal' |awk -F : '{print $2}' |sed 's/^[ t]*//g')
echo -e "Total Memory:n${Total}n${Line}"

#系統支援最大記憶體
Max_Capacity=$(dmidecode -t memory -q |grep 'Maximum Capacity' |awk -F : '{print $2}' |sed 's/^[ t]*//g')
echo -e "Maxinum Memory Capacity:n${Max_Capacity}n${Line}"

#查看記憶體類型、頻率、條數、最大支援記憶體等資訊:dmidecode -t memory,或dmidecode | grep -A16 "Memory Device$"
#下面為統計記憶體條數
Number=$(dmidecode | grep -A16 "Memory Device$" |grep Size|sort |sed 's/^[ t]*//g'| grep -v 'No Module Installed' | wc -l)
echo -e "Number of Physical Memory:n${Number}n${Line}"


#SwapTotal swap分區總大小
SwapTotal=$(cat /proc/meminfo |grep 'SwapTotal' |awk -F : '{print $2}' |sed 's/^[ t]*//g')
echo -e "Total Swap:n${SwapTotal}n${Line}"

#Buffers size
Buffers=$(cat /proc/meminfo |grep 'Buffers' |awk -F : '{print $2}' |sed 's/^[ t]*//g')
echo -e "Buffers:n${Buffers}n${Line}"

#Cached size
Cached=$(cat /proc/meminfo |grep '<Cached>' |awk -F : '{print $2}' |sed 's/^[ t]*//g')
echo -e "Cached:n${Cached}n${Line}"

#空閑記憶體 + buffers/cache
Available=$(free -m |grep - |awk -F : '{print $2}' |awk '{print $2}')
echo -e "Available Memory:n${Available} MBn${Line}"

#顯示硬碟,以及大小
Disk=$(fdisk -l |grep 'Disk' |awk -F , '{print $1}' | sed 's/Disk identifier.*//g' | sed '/^$/d')
echo -e "Amount Of Disks:n${Disk}n${Line}"

#各掛載分區使用方式
Partion=$(df -hlP |sed -n '2,$p')
echo -e "Usage Of partions:n${Partion}n${Line}"



----------------------------------------------------------------------------------------

測試結果展示:

 代碼如下 複製代碼
===========
OS:
Red Hat Enterprise Linux Server release 5.6 (Tikanga)
===========
OS_version:
i686
===========
Kernel_version:
2.6.18-238.el5
===========
CPU model:
AMD A6-3400M APU with Radeon(tm) HD Graphics
===========
Total of physical CPU:
2
===========
Number of CPU cores
2
===========
Number of logical CPUs:
4
===========
Present Mode Of CPU:
32
===========
Support Mode Of CPU:
64
===========
Total Memory:
514744 kB
===========
Maxinum Memory Capacity:
1024 GB
===========
Number of Physical Memory:
1
===========
Total Swap:
1044216 kB
===========
Buffers:
101936 kB
===========
Cached:
267356 kB
===========
Available Memory:
369 MB
===========
Amount Of Disks:
Disk /dev/sda: 107.3 GB
===========
Usage Of partions:
/dev/sda3 96G 4.6G 87G 6% /
/dev/sda1 99M 12M 83M 13% /boot
tmpfs 252M 0 252M 0% /dev/shm
/dev/hdc 3.0G 3.0G 0 100% /media/RHEL_5.6 i386 DVD
===========
相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.