荐一个获取Linux服务器(ubuntu、centos已测试)信息的Shell脚本
2019/10/10/17:46:05 阅读:1759 来源:谷歌SEO算法 标签:
DNS
本文我们来分享一个获取Linux服务器信息的Shell脚本,此脚本已在ubuntu、centos测试通过,本文脚本可以获取Linux发行版本,操作系统是不是64位的.
此脚本已经在ubuntu以及centos版本上测试通过,直接上源代码比较爽:
- #!/bin/bash
- Line='==========='
- #linux发行版名称
- if[[-f/usr/bin/lsb_release]];then
- OS=$(/usr/bin/lsb_release-a|grepDescription|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'modelname'/proc/cpuinfo|uniq|awk-F:'{print$2}'|sed's/^[t]*//g'|sed's/+//g')
- echo-e"CPUmodel:n${CPU}n${Line}"
- #物理cpu个数
- Counts=$(grep'physicalid'/proc/cpuinfo|sort|uniq|wc-l)
- echo-e"TotalofphysicalCPU:n${Counts}n${Line}"
- #物理cpu内核数
- Cores=$(grep'cpucores'/proc/cpuinfo|uniq|awk-F:'{print$2}'|sed's/^[t]*//g')
- echo-e"NumberofCPUcoresn${Cores}n${Line}"
- #逻辑cpu个数
- PROCESSOR=$(grep'processor'/proc/cpuinfo|sort|uniq|wc-l)
- echo-e"NumberoflogicalCPUs:n${PROCESSOR}n${Line}"
- #查看CPU当前运行模式是64位还是32位
- Mode=$(getconfLONG_BIT)
- echo-e"PresentModeOfCPU:n${Mode}n${Line}"
- #查看CPU是否支持64位技术:grep'flags'/proc/cpuinfo,若flags信息中包含lm字段,则支持64位
- Numbers=$(grep'lm'/proc/cpuinfo|wc-l)
- if((${Numbers}>0));thenlm=64
- elselm=32
- fi
- echo-e"SupportModeOfCPU:n${lm}n${Line}"
- ######################################################################
- #Memtotal内存总大小
- Total=$(cat/proc/meminfo|grep'MemTotal'|awk-F:'{print$2}'|sed's/^[t]*//g')
- echo-e"TotalMemory:n${Total}n${Line}"
- #系统支持最大内存
- Max_Capacity=$(dmidecode-tmemory-q|grep'MaximumCapacity'|awk-F:'{print$2}'|sed's/^[t]*//g')
- echo-e"MaxinumMemoryCapacity:n${Max_Capacity}n${Line}"
- #查看内存类型、频率、条数、最大支持内存等信息:dmidecode-tmemory,或dmidecode|grep-A16"MemoryDevice$"
- #下面为统计内存条数
- Number=$(dmidecode|grep-A16"MemoryDevice$"|grepSize|sort|sed's/^[t]*//g'|grep-v'NoModuleInstalled'|wc-l)
- echo-e"NumberofPhysicalMemory:n${Number}n${Line}"
- #SwapTotalswap分区总大小
- SwapTotal=$(cat/proc/meminfo|grep'SwapTotal'|awk-F:'{print$2}'|sed's/^[t]*//g')
- echo-e"TotalSwap:n${SwapTotal}n${Line}"
- #Bufferssize
- Buffers=$(cat/proc/meminfo|grep'Buffers'|awk-F:'{print$2}'|sed's/^[t]*//g')
- echo-e"Buffers:n${Buffers}n${Line}"
- #Cachedsize
- 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"AvailableMemory:n${Available}MBn${Line}"
- #显示硬盘,以及大小
- Disk=$(fdisk-l|grep'Disk'|awk-F,'{print$1}'|sed's/Diskidentifier.*//g'|sed'/^$/d')
- echo-e"AmountOfDisks:n${Disk}n${Line}"
- #各挂载分区使用情况
- Partion=$(df-hlP|sed-n'2,$p')
- echo-e"UsageOfpartions:n${Partion}n${Line}"
测试结果展示,代码如下:
- ===========
- OS:
- RedHatEnterpriseLinuxServerrelease5.6(Tikanga)
- ===========
- OS_version:
- i686
- ===========
- Kernel_version:
- 2.6.18-238.el5
- ===========
- CPUmodel:
- AMDA6-3400MAPUwithRadeon(tm)HDGraphics
- ===========//phpfensi.com
- TotalofphysicalCPU:
- 2
- ===========
- NumberofCPUcores
- 2
- ===========
- NumberoflogicalCPUs:
- 4
- ===========
- PresentModeOfCPU:
- 32
- ===========
- SupportModeOfCPU:
- 64
- ===========
- TotalMemory:
- 514744kB
- ===========
- MaxinumMemoryCapacity:
- 1024GB
- ===========
- NumberofPhysicalMemory:
- 1
- ===========
- TotalSwap:
- 1044216kB
- ===========
- Buffers:
- 101936kB
- ===========
- Cached:
- 267356kB
- ===========
- AvailableMemory:
- 369MB
- ===========
- AmountOfDisks:
- Disk/dev/sda:107.3GB
- ===========
- UsageOfpartions:
- /dev/sda396G4.6G87G6%/
- /dev/sda199M12M83M13%/boot
- tmpfs252M0252M0%/dev/shm
- /dev/hdc3.0G3.0G0100%/media/RHEL_5.6i386DVD
- ===========
热门评论