获取服务器信息的Shell脚本分享(ubuntu、centos测试通过)
此脚本已经在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"NumberofCPUcores\n${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}MB\n${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}"