文章目录
Linux Shell CentOS 查看Linux 硬件的基本信息 写成 sh 脚本1、引入的脚本2、代码脚本3、结果
Linux Shell CentOS 查看Linux 硬件的基本信息 写成 sh 脚本
1、引入的脚本
fun_not_empty
() {
if [ -z
"$1" ]; then
prt
"$2" red
exit 1
fi
}
2、代码脚本
fun_next
() {
prt
"\n"
prt
"\n"
prt
"\n"
}
fun_title_line
() {
prt
"--------------------- $1 ---------------------"
}
fun_title_line
prt
"# @"
prt
"# 查看电脑相关的概要操作系统信息"
prt
"# CPU"
prt
"# 内存"
prt
"# 磁盘"
prt
"# 操作系统"
prt
"# 网络"
prt
"# 防火墙"
prt
"# @"
fun_title_line
fun_next
fun_title_line
"CPU"
prt
"有几个逻辑 CPU 以及 CPU 型号 CPU 主频"
cat /proc/cpuinfo
| grep name
| cut -f2 -d:
| uniq -c
prt
"CPU 模型名称"
more /proc/cpuinfo
| grep "model name"
prt
"CPU 当前的工作模式是 32 位还是 64位"
getconf LONG_BIT
prt
"CPU 是否支持 64 位计算,大于 0 为支持"
cat /proc/cpuinfo
| grep flags
| grep ' lm ' | wc -l
fun_next
fun_title_line
"内存"
prt
"内存总量 KB"
grep MemTotal /proc/meminfo
prt
"内存总量 MB"
free -m
| grep "Mem" | awk '{print $2}'
fun_next
fun_title_line
"磁盘"
prt
"硬盘和分区信息"
df -h
prt
"# "
fdisk -l
fun_next
fun_title_line
"操作系统"
prt
"操作系统名称 \c"
uname -s
prt
"计算机名称 \c"
uname -n
prt
"操作系统发行编号 \c"
uname -r
prt
"操作系统发行时间 \c"
uname -v
prt
"计算机类型 \c"
uname -m
prt
"进程类型 \c"
uname -r
prt
"硬件平台 \c"
uname -p
prt
"操作系统信息 \c"
uname -i
prt
"版本信息 \c"
uname --version
prt
"操作系统当前时间 \c"
date
fun_next
fun_title_line
"网络"
prt
"需要支持 ifconfig 命令"
prt
"当前机器的 IPV4 地址有"
ifconfig | grep "inet "
fun_next
fun_title_line
"防火墙"
prt
"当前防火墙状态 "
systemctl status firewalld.service
| grep "Active: active (running)"
systemctl status firewalld.service
| grep "Active: active (running)" && prt
"防火墙处于开启状态" || prt
"防火墙处于关闭状态"
systemctl status firewalld.service
| grep "Active: active (running)" && prt
"已开启的端口有" && firewall-cmd --zone
=public --list-ports
fun_next
3、结果
简简单单OnlineZuozuo
认证博客专家
Spring
架构
分布式
未闻万里蓬莱,而窥先圣遗智。故,以此生筑梦,奔而逐之;以泰山之伟,攀而登之;以静雅素心,处世为人。------zuozuo著