Recommend a shell script to get the Linux server (Ubuntu, CentOS tested) information

Source: Internet
Author: User

This script has been tested on the Ubuntu and CentOS versions, and the source code is much more straightforward:

The code is as follows Copy Code
#!/bin/bash

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

#linux发行版名称
if [[-f/usr/bin/lsb_release]]; Then
os=$ (/usr/bin/lsb_release-a |grep Description |awk-f: ' {print $} ' |sed ' s/^[t]*//g ')
Else
os=$ (cat/etc/issue |sed-n ' 1p ')
Fi

Echo-e "${line}nos:n${os}n${line}"

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

#查看系统是否为64位: Uname-m, if x86_64 is present, it is 64 digits.
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 $} ' |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 $} ' |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, support for 64-bit if the flags information contains LM fields
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 Memory Size
total=$ (cat/proc/meminfo |grep ' memtotal ' |awk-f: ' {print $} ' |sed ' s/^[t]*//g ')
Echo-e "Total Memory:n${total}n${line}"

#系统支持最大内存
max_capacity=$ (dmidecode-t memory-q |grep ' Maximum Capacity ' |awk-f: ' {print $} ' |sed ' s/^[t]*//g ')
Echo-e "Maxinum Memory Capacity:n${max_capacity}n${line}"

#查看内存类型, frequency, number, maximum support memory, and other information: dmidecode-t memory, or 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}"


Total size of #SwapTotal swap partition
swaptotal=$ (cat/proc/meminfo |grep ' swaptotal ' |awk-f: ' {print $} ' |sed ' s/^[t]*//g ')
Echo-e "Total Swap:n${swaptotal}n${line}"

#Buffers size
buffers=$ (cat/proc/meminfo |grep ' buffers ' |awk-f: ' {print $} ' |sed ' s/^[t]*//g ')
Echo-e "Buffers:n${buffers}n${line}"

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

#空闲内存 + Buffers/cache
available=$ (free-m |grep-|awk-f: ' {print $} ' |awk ' {print $} ')
Echo-e "Available memory:n${available} Mbn${line}"

#显示硬盘, and size
disk=$ (fdisk-l |grep ' Disk ' |awk-f, ' {print $} ' | 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}"



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

Test results show:

The code is as follows Copy Code
===========
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 CPUs:
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
===========
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.