檢測伺服器物理機CPU是否滿足超頻

AMlyq發表於2020-09-25

#!/bin/bash
#dpkg -l | grep -w bc >/dev/null 2>&1 || echo -e "\033[31m install bc \033[0m" && sudo apt-get install bc >/dev/null 2>&1
ModelNameMHz=`cat /proc/cpuinfo | grep "model name" | awk '{print $10}'| sed 's/GHz//'  | head -n 1`
ModelNameMHzsum=`cat /proc/cpuinfo | grep "model name" | awk '{print $10}'| sed 's/GHz//' | wc -l`
sum=0
for (( a = 0; a < 10; a++ )); do
    #echo "第$(($a+1))組 CheckCPU_MHz"
    CPUMHz=(`cat /proc/cpuinfo | grep "cpu MHz" | awk '{print $4}'`)
    for (( i = 0; i < $ModelNameMHzsum; i++ )); do
        CPU=`echo "$ModelNameMHz*1000" | bc`
        if [ $(echo "${CPUMHz[i]} < $CPU" | bc) -eq 1 ]; then
            #echo "${CPUMHz[i]}"
            t=$((t+1))
        fi
    done
    unset CPUMHz
    sleep 1
    sum=$((${sum} + t))
    t=0
    #echo $sum
done

while [[ "$sum" == 0 ]]; do
    echo -e "`hostname` 單核MHz均大於$ModelNameMHz標準HMz"
    exit 0
done
while [[ "$sum" != 0 ]]; do
    echo -e "`hostname` 不是超頻!!!!"
    exit 0
done

相關文章