Shell脚本查看主机软硬件资源信息
作者:互联网
带学生做实验时常用到的信息,不保证完全满足特定工作场景需求,欢迎补充并更新脚本内容。
shell脚本运行截图:
程序代码:
echo "################ README INFO ############################"
echo "### Purpose: A display information of system resource ###"
echo "### Made By: PomanTeng ###"
echo "### E-mail: denggongmengbo@gmail.com ###"
echo "### WeChat: 1807479153 ###"
echo "### Version Identification Number:V0.00 ###"
echo "### Procedure Identification Number:20210409 ###"
echo "#########################################################"
echo "*****主板型号*****"
dmidecode |grep -A16 "System Information$"
echo "*****OS信息概览*****"
lsb_release -a
echo "*****物理CPU的个数*****"
cat /proc/cpuinfo | grep "physical id" | sort | uniq | wc -l
echo "*****逻辑CPU的个数*****"
cat /proc/cpuinfo | grep "processor" | wc -l
echo "*****CPU核心数*****"
cat /proc/cpuinfo | grep "cores" | uniq
echo "*****CPU的主频*****"
cat /proc/cpuinfo | grep MHz | uniq
echo "*****CPU型号特征*****"
cat /proc/cpuinfo | grep name | cut -f2 -d: | uniq -c
echo "*****当前CPU运行模式*****"
getconf LONG_BIT
echo "*****内存与交换分区信息*****"
cat /proc/meminfo | grep -E 'MemTotal|MemFree|MemAvailable|SwapTotal|SwapFree'
echo "*****物理内存信息列表*****"
dmidecode | grep -A16 "Memory Device$"
echo "*****最大支持内存*****"
dmidecode -t 16
echo "*****磁盘及分区信息*****"
fdisk -l | grep -E "Disklabel type|Disk model|Disk identifier|Disk /dev/sd" && df -h | grep -E '/dev/sd'
echo "*****主机信息概览*****"
hostnamectl status
echo "*****分区挂载状态*****"
mount | column -t
echo "*****系统平均负载各项数据的含义:1分钟内、5分钟内、15分钟内的平均进程数;运行的进程数比上进程总数;最近运行的进程ID*****"
cat /proc/loadavg
echo "*****系统资源负载各项数据的含义:当前系统时间;系统运行时间;正在登陆系统的用户数;过去1分钟平均负载;过去5分钟平均负载;过去15分钟平均负载*****"
uptime
echo "*****路由表*****"
route -n
echo "*****网卡状态信息*****"
ip link
ifconfig
echo "*****展示所有监听端口*****"
netstat -lntp
echo "*****当前活动用户*****"
w
echo "*****用户登录日志*****"
last
echo "*****展示所有用户*****"
cut -d: -f1 /etc/passwd
echo "*****展示所有组*****"
cut -d: -f1 /etc/group
echo "*****Ubuntu 16.04 后 chkconfig 已经被 sysv-rc-conf 替代*****"
cp /etc/apt/sources.list{,.original}
echo "***当前软件源列表***"
grep "^\s*[^# \t].*$" /etc/apt/sources.list | cat -n
echo "deb http://archive.ubuntu.com/ubuntu/ focal main universe restricted multiverse" >> /etc/apt/sources.list
echo "deb http://archive.ubuntu.com/ubuntu/ trusty main universe restricted multiverse" >> /etc/apt/sources.list
echo "***修改后的软件源列表***"
grep "^\s*[^# \t].*$" /etc/apt/sources.list | cat -n
apt-get update
apt-get install -y sysv-rc-conf
sysv-rc-conf --list | grep on
标签:Shell,grep,主机,echo,etc,软硬件,cat,proc,### 来源: https://blog.51cto.com/u_6286393/2695228