查看系统信息脚本

osinfo.sh

#!/bin/bash
echo -e "-------------------------------System Information----------------------------"
echo -e "Hostname:\t\t"`hostname`
echo -e "uptime:\t\t"`uptime | awk '{print $3,$4}' | sed 's/,//'`
echo -e "Manufacturer:\t"`cat /sys/class/dmi/id/chassis_vendor`
echo -e "Product Name:\t"`cat /sys/class/dmi/id/product_name`
echo -e "Version:\t\t"`cat /sys/class/dmi/id/product_version`
echo -e "Serial Number:\t"`cat /sys/class/dmi/id/product_serial`
echo -e "Machine Type:\t"`vserver=$(lscpu | grep Hypervisor | wc -l); if [ $vserver -gt 0 ]; then echo "VM"; else echo "Physical"; fi`
echo -e "Operating System:\t"`hostnamectl | grep "Operating System" | cut -d ' ' -f5-`
echo -e "Kernel:\t\t"`uname -r`
echo -e "Architecture:\t"`arch`
echo -e "Processor Name:\t"`awk -F':' '/^model name/ {print $2}' /proc/cpuinfo | uniq | sed -e 's/^[ \t]*//'`
echo -e "Active User:\t\t"`w | cut -d ' ' -f1 | grep -v USER | xargs -n1`
echo -e "System Main IP:\t"`hostname -I`
echo ""
echo -e "-------------------------------CPU/Memory Usage------------------------------"
echo -e "Memory Usage:\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 Usage:\t\t"`cat /proc/stat | awk '/cpu/{printf("%.2f%\n"), ($2+$4)*100/($2+$4+$5)}' |  awk '{print $0}' | head -1`
echo ""
echo -e "-------------------------------Disk Usage >80%-------------------------------"
df -hl 
echo ""
echo -e "-------------------------------For WWN Details-------------------------------"
vserver=$(lscpu | grep Hypervisor | wc -l)
if [ $vserver -gt 0 ]
then
echo "$(hostname) is a VM"
else
cat /sys/class/fc_host/host?/port_name
fi

执行:

sudo sh osinfo.sh

显示

-e -------------------------------System Information----------------------------
-e Hostname:		deepin
-e uptime:		1 day
-e Manufacturer:	LENOVO
-e Product Name:	80RU
-e Version:		Lenovo ideapad 700-15ISK
-e Serial Number:	R90JSUXSR9N0B620200R
-e Machine Type:	Physical
-e Operating System:	Deepin 15
-e Kernel:		4.15.0-30deepin-generic
-e Architecture:	x86_64
-e Processor Name:	Intel(R) Core(TM) i5-6300HQ CPU @ 2.30GHz
-e Active User:		xxx
-e System Main IP:	192.168.xx.xx

-e -------------------------------CPU/Memory Usage------------------------------
-e Memory Usage:	22.91%
-e Swap Usage:		0.00%
-e CPU Usage:		2.47%

-e -------------------------------Disk Usage >80%-------------------------------
文件系统        容量  已用  可用 已用% 挂载点
udev            3.8G     0  3.8G    0% /dev
tmpfs           777M  1.7M  776M    1% /run
/dev/sda8       229G   11G  207G    5% /
tmpfs           3.8G   61M  3.8G    2% /dev/shm
tmpfs           5.0M  4.0K  5.0M    1% /run/lock
tmpfs           3.8G     0  3.8G    0% /sys/fs/cgroup
/dev/sda1        95M   31M   65M   32% /boot/efi
tmpfs           777M   32K  777M    1% /run/user/1000
/dev/sda4        73G   52M   69G    1% /media/cdq/f21e88e7-c460-374b-8a0e-a2811d8923da
/dev/sda3       407G  317G   91G   78% /media/cdq/系统文件
/dev/sda7       201G   54G  147G   27% /media/cdq/办公
/dev/sda6        17G   44M   16G    1% /media/cdq/2bf6971c-943c-f941-955f-d52a2aa5a29e

-e -------------------------------For WWN Details-------------------------------
cat: '/sys/class/fc_host/host?/port_name': 没有那个文件或目录

参考链接:
https://www.jianshu.com/p/da4ca0a6ed1f

posted @ 2020-05-12 12:38  多弗朗强哥  阅读(244)  评论(0编辑  收藏  举报