文章目录

1 代码块


#!/bin/bash

echo "---------------------BEGIN--------------------------"
echo -e "\033[40;31m This script queries the number of CPU cores and vendors, total memory size, and total disk size! \033[0m"

echo "----------------------CPU--------------------------"
# CPU核数
cores=`cat /proc/cpuinfo | grep -w processor | wc -l`
vendor=`cat /proc/cpuinfo | grep vendor_id | uniq | tr -s " " | cut -d " " -f 2`
if [[ $vendor=="Genuinelnmtel" ]];then
echo "CPU is Intel!,CPU cores is $cores"
elif [[ $vendor=="AuthenticAMD" ]];then
echo "CPU is AMD!,CPU cores is $cores"
else
echo "CPU is Other!,CPU cores is $cores"
fi
echo""
echo "----------------------Mem---------------------------"
# 查看当前总内存
MemTotal=`awk -F' ' 'NR==1{print$2}' /proc/meminfo`
if [[ $MemTotal -ge 1024 ]];then
# 1024=MB
Mem=`echo $[MemTotal/1024]`
echo "MemTotal is $Mem MB"
elif [[ $MemTotal -ge 1048576 ]];then
# 1,048,576=GB
Mem=`echo $[MemTotal/1048576]`
echo "MemTotal is $Mem GB"
elif [[ $MemTotal -ge 1073741824 ]];then
# 1,073,741,824=TB
Mem=`echo $[MemTotal/1073741824]`
echo "MemTotal is $Mem TB"
fi
echo""
echo "----------------------DISK--------------------------"
fdisk -l | grep -E '^Disk' | grep -Ev "mapper|label|identifier|Virtual" | awk -F' ' '{print $2,$3,$4}'
echo "----------------------END---------------------------"

2 执行结果


Shell ❀ 校验服务器CPU、内存、硬盘总大小脚本_bash