查看Linux系统信息脚本(运维)

导游

    • 前言
    • 脚本内容
    • 执行效果
    • 图片效果

查看Linux系统信息脚本(运维)_第1张图片

前言

这是一个查看Linux系统硬件信息的shell脚本。

脚本内容

#!/bin/bash
#description:system_info
echo -e "-------------------------------System Information----------------------------"
echo -e "Hostname:\t\t"`hostname`
echo -e "uptime:\t\t\t"`uptime | awk '{print $3,$4}' | sed 's/,//'`
echo -e "Manufacturer:\t\t"`cat /sys/class/dmi/id/chassis_vendor`
echo -e "Product Name:\t\t"`cat /sys/class/dmi/id/product_name`
echo -e "Product Version:\t"`cat /sys/class/dmi/id/product_version`
echo -e "Serial Number:\t\t"`cat /sys/class/dmi/id/product_serial`
lscpu | grep VMware &>/dev/null
echo -e "Machine Type:\t\t"`if [ $? -eq 0 ]; then echo "VMware"; else echo "Physical"; fi`
echo -e "Operating System:\t"`hostnamectl | grep "Operating System" | cut -d ' ' -f5-`
echo -e "Version:\t\t"`cat /etc/redhat-release `
echo -e "Kernel:\t\t\t"`uname -r`
echo -e "Architecture:\t\t"`arch`
echo -e "Processor Name:\t\t"`awk -F':' '/^model name/ {print $2}' /proc/cpuinfo | uniq | sed -e 's/^[ \t]*//'`
echo -e "processor number:\t"`cat /proc/cpuinfo | grep processor | wc -l`
echo -e "Active User:\t\t"`w | cut -d ' ' -f1 | grep -v USER | xargs -n1`
echo -e "System Main IP:\t\t"`hostname -I`
echo ""
echo -e "-------------------------------CPU/Memory Usage------------------------------"
echo -e "Memory Usage:\t\t"`free | awk '/Mem/{printf("%.2f%"), $3/$2*100}'`
echo -e "Swap Usage:\t\t"`free | awk '/Swap/{printf("%.2f%"), $3/$2*100}'`
echo -e "CPU Free Space:\t\t"`top -bn 1 -i -c | grep ^% |cut -f4 -d, | awk '{print $1}'`%

echo ""
echo -e "-------------------------------Disk Usage>50%-------------------------------"
df -Ph | sed s/%//g | awk '{ if($5 > 50) print $0;}'
echo ""

执行效果

注:以下为虚拟机中的执行结果

sh system.info.sh 
-------------------------------System Information----------------------------
Hostname:		linux.node2
uptime:			3:47 2
Manufacturer:		No Enclosure
Product Name:		VMware Virtual Platform
Product Version:	None
Serial Number:		VMware-56 4d 4d e4 9a 5f 28 8c-31 f5 65 40 73 6d 2a 38
Machine Type:		VMware
Operating System:	CentOS Linux 7 (Core)
Version:		CentOS Linux release 7.7.1908 (Core)
Kernel:			3.10.0-1062.el7.x86_64
Architecture:		x86_64
Processor Name:		Intel(R) Core(TM) i5-8300H CPU @ 2.30GHz
processor number:	2
Active User:		root root
System Main IP:		192.168.1.124 192.168.122.1

-------------------------------CPU/Memory Usage------------------------------
Memory Usage:		35.39%
Swap Usage:		0.00%
CPU Free Space:		96.9%

-------------------------------Disk Usage>50%-------------------------------
文件系统                       容量  已用  可用 已用 挂载点
/dev/sr0                       4.4G  4.4G     0  100 /mnt


图片效果

查看Linux系统信息脚本(运维)_第2张图片

你可能感兴趣的:(shell脚本)