Articles
Server and Storage Administration
Return to "How to Use the Power Management Controls on SPARC CMT Servers"
#!/bin/ksh # # This script gets or sets the power management policy for # one or more systems. A time schedule can be setup in # CRON to select a policy and time period for the policy to # be in effect. This script can also be ran manually. # # The system IP(s) or hostname(s) for the Service Processor(s) of the # host system(s) is populated in the default file /tmp/spips, which # be changed on the command line. # # Input: # -h: Help message # -f: File contains the SP(s) IP/hostname
# -g: Get the current policy
# -e: Set Elastic policy
# -p: Set Performance policy
ELASTIC="elastic"
MIBPOLICY=" sunHwCtrlPowerMgmtPolicy.0 "
PERFORMANCE="performance"
SNMPGET=snmpget
SNMPOPTS=" -v2c -cprivate "
SNMPSET=snmpset
SNMP_ELASTIC=4
SNMP_PERFORMANCE=3
SRC_FILE="/tmp/spips"
path=`echo $PATH`
path="${path}:/usr/sfw/bin"
export PATH=$path
snmpconf=`env | grep SNMPCONFPATH`
if [ -z $snmpconf ]
then
echo "No SNMPCONFPATH in ENV. Please export the SNMPCONFPATH"
echo "variable to point to a snmp.conf file that contains the"
echo "location of the MIB files."
exit 2
fi
eflg= gflg=
plfg=
while getopts hpegf: polopt
do
case $polopt in
e) eflg=1;;
f) SRC_FILE=$OPTARG;;
g) gflg=1;;
p) pflg=1;;
h) echo "\nUSAGE: policy -h -e -g -p -f"
echo "\t-h: This Help message"
echo "\t-f: File of SP IP or hostnames to manage"
echo "\t-g: Get the current policy"
echo "\t-e: Set Elastic policy"
echo "\t-p: Set Performance policy"
exit 1;;
*) echo "Invalid option $polopt\n"; exit 2;;
esac
done
# Loop through all SPs and get or set the policy
while read host
do
if [[ ! -z $gflg ]]; then
# Get the current policy
# SUN-HW-CTRL-MIB::sunHwCtrlPowerMgmtPolicy.0 = INTEGER: elastic(4)
result=`$SNMPGET $SNMPOPTS $host $MIBPOLICY`
policy_tmp=${result##*: }
policy=${policy_tmp%\(*\)}
echo "`date`: policy == $policy for SP $host"
fi
if [[ ! -z $eflg ]]; then
# Set Elastic policy
result=`$SNMPSET $SNMPOPTS $host $MIBPOLICY = $SNMP_ELASTIC`
policy_tmp=${result##*: }
policy=${policy_tmp%\(*\)}
# Verify Elastic was set
if [[ $policy != $ELASTIC ]]; then
echo "`date`: Failed to set $ELASTIC policy for SP $host"
else
echo "`date`: Set $ELASTIC policy for SP $host"
fi
elif [[ ! -z $pflg ]]; then
# Set Performance policy
result=`$SNMPSET $SNMPOPTS $host $MIBPOLICY = $SNMP_PERFORMANCE`
policy_tmp=${result##*: }
policy=${policy_tmp%\(*\)}
# Verify Performance was set
if [[ $policy != $PERFORMANCE ]]; then
echo "`date`: Failed to set $PERFORMANCE policy for SP $host"
else
echo "`date`: Set $PERFORMANCE policy for SP $host"
fi
fi
done < $SRC_FILE