Skip to content

Instantly share code, notes, and snippets.

@adaiguoguo adaiguoguo/power_check.sh
Last active Sep 6, 2016

Embed
What would you like to do?
检查宿主是否有cpu时钟休眠
#!/bin/bash
#
pro=$(dmidecode -t 1|grep Manufacturer|awk '{print $2}')
sys=$(lsb_release -a|grep ID |awk '{print $3}')
ver=$(lsb_release -a|grep Release|awk '{print $2}'|awk -F '.' '{print $1}')
if [[ $pro == Dell ]]
then
if [[ $sys == "CentOS" ]]
then
/opt/dell/toolkit/bin/syscfg --SysProfile 2>/dev/null |grep -q "perfoptimized$"
if [[ $? == 0 ]]
then
echo -e "0"
exit 0
fi
/opt/dell/toolkit/bin/syscfg --pendingvalues 2>/dev/null |grep -q PerfOptimized
if [[ $? == 0 ]]
then
echo -e "1"
exit 1
fi
type /opt/dell/toolkit/bin/syscfg &>/dev/null
if [[ $? != 0 ]]
then
echo -e "2"
exit 2
fi
echo -e "2"
exit 2
elif [[ $sys == "Ubuntu" ]]
then
echo -e "0"
exit 0
else
echo -e "0"
exit 0
fi
elif [[ $pro == "HP" ]]
then
if [[ $sys == "CentOS" ]]
then
cd /tmp
conrep -h &>/dev/null
if [[ $? != 0 ]]
then
echo "2"
exit 2
fi
#hplog -h &>/dev/null
#if [[ $? != 0 ]]
#then
# echo "2"
# exit 2
#fi
if [[ -f /dev/shm/hp_power_change ]]
then
echo 1
exit 1
fi
conrep -s >/dev/null
cat /tmp/conrep.dat |grep -i profile|grep -q "Maximum_Performance"
if [[ $? -ge 0 ]]
then
echo 0
exit 0
else
sed -i -e 's#<Section name="HP_Power_Profile" helptext="Selects the level of power versus performance for the system.">.*</Section>#<Section name="HP_Power_Profile" helptext="Selects the level of power versus performance for the system.">Maximum_Performance</Section>#' conrep.dat
conrep -l -f conrep.dat >/dev/null
touch /dev/shm/hp_power_change
echo 1
exit 1
fi
elif [[ $sys == "Ubuntu" ]]
then
echo 0
exit 0
else
echo 0
exit 0
fi
elif [[ $pro == "Huawei" ]]
then
echo 0
exit 0
else
echo 0
exit 0
fi
┏( ̄▽ ̄)┛  ~  cat power_check.sh
#!/bin/bash
#check linux power set to performance
#write by lishuai
lsb_release &>/dev/null || yum install -y redhat-lsb
pro=$(dmidecode -t 1|grep Manufacturer|awk '{print $2}')
sys=$(lsb_release -a|grep ID |awk '{print $3}')
ver=$(lsb_release -a|grep Release|awk '{print $2}'|awk -F '.' '{print $1}')
if [[ $pro == "KVM" ]]
then
echo 0
exit 0
fi
if [[ $sys == "Ubuntu" ]]
then
echo 0
exit 0
fi
if [[ $ver -gt 6 ]]
then
freq_count=$(cpupower -c all frequency-info|grep "use$"|grep -v performance|wc -l)
idle_count=$(cpupower -c all idle-info|grep ":$"|grep -v Analyzing |grep -v DISABLED|wc -l)
let count=$freq_count+$idle_count
echo $count
#exit $count
else
freq_count=$(cpupower -c all frequency-info|grep "use$"|grep -v performance|wc -l)
echo $freq_count
#exit $freq_count
fi
#!/bin/bash
#
pro=$(dmidecode -t 1|grep Manufacturer|awk '{print $2}')
sys=$(lsb_release -a|grep ID |awk '{print $3}')
ver=$(lsb_release -a|grep Release|awk '{print $2}'|awk -F '.' '{print $1}')
if [[ $pro == Dell ]]
then
if [[ $sys == "CentOS" ]]
then
/opt/dell/toolkit/bin/syscfg --SysProfile 2>/dev/null |grep -q "perfoptimized$"
if [[ $? == 0 ]]
then
echo -e "0"
exit 0
fi
/opt/dell/toolkit/bin/syscfg --pendingvalues 2>/dev/null |grep -q PerfOptimized
if [[ $? == 0 ]]
then
echo -e "1"
exit 1
fi
type /opt/dell/toolkit/bin/syscfg &>/dev/null
if [[ $? != 0 ]]
then
echo -e "2"
exit 2
fi
echo -e "2"
exit 2
elif [[ $sys == "Ubuntu" ]]
then
echo -e "0"
exit 0
else
echo -e "0"
exit 0
fi
elif [[ $pro == "HP" ]]
then
if [[ $sys == "CentOS" ]]
then
cd /tmp
conrep -h &>/dev/null
if [[ $? != 0 ]]
then
echo "2"
exit 2
fi
#hplog -h &>/dev/null
#if [[ $? != 0 ]]
#then
# echo "2"
# exit 2
#fi
if [[ -f /dev/shm/hp_power_change ]]
then
echo 1
exit 1
fi
conrep -s >/dev/null
cat /tmp/conrep.dat |grep -i profile|grep -q "Maximum_Performance"
if [[ $? -ge 0 ]]
then
echo 0
exit 0
else
sed -i -e 's#<Section name="HP_Power_Profile" helptext="Selects the level of power versus performance for the system.">.*</Section>#<Section name="HP_Power_Profile" helptext="Selects the level of power versus performance for the system.">Maximum_Performance</Section>#' conrep.dat
conrep -l -f conrep.dat >/dev/null
touch /dev/shm/hp_power_change
echo 1
exit 1
fi
elif [[ $sys == "Ubuntu" ]]
then
echo 0
exit 0
else
echo 0
exit 0
fi
elif [[ $pro == "Huawei" ]]
then
echo 0
exit 0
else
echo 0
exit 0
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.