1 Star 0 Fork 0

悳LL/checksh

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
check_kj.sh 5.44 KB
一键复制 编辑 原始数据 按行查看 历史
悳LL 提交于 2023-03-14 06:46 . update check_kj.sh.
#!/bin/bash
#判断cpu核心数是否小于64
cpu_number=`lscpu |grep "CPU(s):" |head -n1 |awk '{print $2}'`
if [ $cpu_number -lt 64 ];then
echo -e "\033[41m --------------------->>>>> 【cpu核心数小于64 ERROR!】 \033[0m"
else
echo -e "\033[32m --------------------->>>>> 【cpu核心数 OK!cpu_number=$cpu_number\033[0m"
fi
#判断cpu主频是否异常
cpu_MHz=`lscpu | grep "CPU MHz" | awk '{print $3}' | awk -F '.' '{print $1}'`
if [ $cpu_MHz -lt 1200 ]; then
echo -e "\033[41m --------------------->>>>> 【CPU主频 异常 ERROR!】 \033[0m"
else
echo -e "\033[32m --------------------->>>>> 【CPU主频 OK!】 \033[0m"
fi
##CPU socket/NUMA 校验
CPU_socket=`lscpu | grep "Socket" | awk '{print $2}'`
NUMA=`lscpu | grep "NUMA node(s)" | awk '{print $3}'`
if [ "${CPU_socket}" -eq "$NUMA" ]; then
echo -e "\033[32m --------------------->>>>> 【CPU-socket/NUMA OK!】 \033[0m"
else
echo -e "\033[41m --------------------->>>>> 【CPU-socket/NUMA ERROR!】 \033[0m"
fi
#判断根目录是否在sda
ifsda=`lsblk |grep "sda\|lvm" |grep "/$" |wc -l`
if [ $ifsda -ne 1 ];then
echo -e "\033[41m --------------------->>>>> 【系统盘不是sda ERROR!】 \033[0m"
else
echo -e "\033[32m --------------------->>>>> 【系统盘是sda OK!】 \033[0m"
fi
##判断是否有磁盘故障
dmesg | grep "Unrecovered read error" | awk '{print $4}' | sort | uniq -c | cut -d '[' -f 2 | cut -d ']' -f 1 > /tmp/a.txt
dmesg | grep 'initial error at time' | cut -d '(' -f 2 | cut -d ')' -f 1 | sort | uniq -c | awk '{print $2}' >> /tmp/a.txt
dmesg | grep "Buffer I/O error on dev" | awk '{print $7}' | sort | uniq -c | awk '{print $2}' | awk -F ',' '{print $1}' >> /tmp/a.txt
dmesg | grep "Buffer I/O error on dev" | awk '{print $8}' | sort | uniq -c | awk '{print $2}' | awk -F ',' '{print $1}' >> /tmp/a.txt
dmesg |grep -i "error" | grep -i "sd" | grep "dev[ ]sd[a-z]" |sed -r 's/(.*)(dev[ ]sd[a-z])(.*)/\2/g' |sort |uniq -c |awk '{print $3}' >>/tmp/a.txt
dmesg |grep "error (device" |awk -F")" '{print $1}' |awk '{print $NF}' |sort |uniq >>/tmp/a.txt
sed -r -i '/logical/d' /tmp/a.txt
for i in `cat /tmp/a.txt | sort | uniq -c | grep -v 'dev' |awk '{print $2}'`
do
echo -e "\033[41m --------------------->>>>> 【$i磁盘报错,确认是否换盘 ERROR!】 \033[0m"
done
rm -rf /tmp/a.txt
#判断是否有内存故障
mem_error=`dmesg |grep -i "CE memory \(scrubbing\)\|\(read\) error on" |awk '{print $10$11$12}' |sort |uniq -c |awk '{print $2}' |head -n 1 |wc -l`
men_total=`free -g |grep ^Mem |awk '{print $2}'`
if [ $mem_error -eq 0 ];then
mem_error=`dmesg |grep "Hardware Error" |wc -l`
if [ $mem_error -lt 8 ];then
echo -e "\033[32m --------------------->>>>> 【内存无报错 OK!,men_total=${men_total}GB】 \033[0m"
else
echo -e "\033[41m --------------------->>>>> 【内存报错 ERROR!,men_total=${men_total}GB】 \033[0m"
fi
else
echo -e "\033[41m --------------------->>>>> 【内存报错 ERROR!,men_total=${men_total}GB】 \033[0m"
fi
##判断内存是否为双数
all_siez=0
for i in `dmidecode | grep 'Ending Address' -B1 -A2 |grep 'Physical Array Handle' -B1 |grep "Range Size" |awk '{print $3}'`
do
let all_size+=i
done
mem_number=`dmidecode | grep 'Ending Address' -B1 -A2 |grep 'Physical Device Handle' -B1 |grep "Range Size" |awk '{print $3}' |sort |uniq -c |wc -l`
if [ $mem_number -ne 0 ];then
mem_size=`dmidecode | grep 'Ending Address' -B1 -A2 |grep 'Physical Device Handle' -B1 |grep "Range Size" |awk '{print $3}' |sort |uniq -c |awk '{print $2}'`
if [ $mem_number -eq 1 ];then
a=`expr $all_size / $mem_size`
if [ $[ $a % 2 ] != 0 ];then
echo -e "\033[41m --------------------->>>>> 【内存数量为奇数,number=$a size=${mem_size}GB all_size=${all_size}GB ERROR!】 \033[0m"
else
echo -e "\033[32m --------------------->>>>> 【内存数量为偶数 ok ,number=$a size=${mem_size}GB all_size=${all_size}GB】 \033[0m"
fi
else
echo -e "\033[41m --------------------->>>>> 【内存大小不一致 ERROR!】 \033[0m"
fi
fi
#判断是否有cpu故障
cpu_error1=`dmesg |grep -i "CMCI storm subsided: switching to interrupt mode" |head -n 1 |wc -l`
cpu_error2=`dmesg |grep -i "CMCI storm detected: switching to poll mode" |head -n 1 |wc -l`
if [ $cpu_error1 -eq 1 ] && [ $cpu_error2 -eq 1 ];then
echo -e "\033[41m --------------------->>>>> 【cpu报错 ERROR!】 \033[0m"
else
echo -e "\033[32m --------------------->>>>> 【cpu无报错 OK!】 \033[0m"
fi
#判断网卡做bond是否正确
bond_check=`ls /etc/sysconfig/network-scripts/| grep "ifcfg-bond-bond0*"|wc -l `
if [ $bond_check = 1 ];then
echo -e "\033[32m --------------------->>>>> 【bond配置 OK!】 \033[0m"
else
echo -e "\033[41m --------------------->>>>> 【bond配置有错!】 \033[0m"
fi
#判断DNS是否配置
dns_check=`cat /etc/sysconfig/network-scripts/ifcfg-bond-bond0| grep "DNS1"|wc -l `
if [ $dns_check = 1 ];then
echo -e "\033[32m --------------------->>>>> 【dns配置 OK!】 \033[0m"
else
echo -e "\033[41m --------------------->>>>> 【dns配置有误!】 \033[0m"
fi
#判断硬盘数量
hd=`lsblk |grep "^sd"|wc -l`
nv=`lsblk |grep "^nv"|wc -l`
if [ $hd = 12 ];then
echo -e "\033[32m --------------------->>>>> 【机械盘 OK!】 \033[0m"
else
echo -e "\033[41m --------------------->>>>> 【机械盘缺失 hdsl=$hd!】 \033[0m"
fi
if [ $nv = 2 ];then
echo -e "\033[32m --------------------->>>>> 【NVME盘 OK!】 \033[0m"
else
echo -e "\033[41m --------------------->>>>> 【NVME盘缺失 nvsl=$nv!】 \033[0m"
fi
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Shell
1
https://gitee.com/qdx9391/checksh.git
git@gitee.com:qdx9391/checksh.git
qdx9391
checksh
checksh
master

搜索帮助