Update power.inc.sh
This commit is contained in:
132
inc/power.inc.sh
132
inc/power.inc.sh
@@ -860,75 +860,73 @@ PDUCONTROL(){
|
||||
DIVIDER . yellow 75
|
||||
echo -e "${idsCL[Yellow]}APC-PDU Power Control"
|
||||
DIVIDER true yellow 75
|
||||
[ "${PORT_SEL}" != "" ] && PORTSEL=${PORT_SEL}
|
||||
if [ "${PORTSEL}" == "" ]; then
|
||||
PORT_DESC=$(snmpwalk -t 1 -r 0 -v 1 -c public ${PW_APCPDU_IP} .1.3.6.1.4.1.318.1.1.12.3.3.1.1.2 -O vq 2> /dev/null | sed -e 's/"//g')
|
||||
PORT_POWER=$(snmpwalk -t 1 -r 0 -v 1 -c public ${PW_APCPDU_IP} .1.3.6.1.4.1.318.1.1.12.3.3.1.1.4 -O vq 2> /dev/null | sed -e 's/"//g')
|
||||
IFS=$'\n'
|
||||
read -rd '' -a PORT_DESC <<<"${PORT_DESC}"
|
||||
read -rd '' -a PORT_POWER <<<"${PORT_POWER}"
|
||||
unset IFS
|
||||
for p in "${!PORT_DESC[@]}"; do
|
||||
port=$(expr ${p} + 1)
|
||||
[ ${PORT_POWER[${p}]} -eq 1 ] && portpower_disp="${idsCL[Green]}ON" || portpower_disp="${idsCL[LightRed]}OFF"
|
||||
[ ${port} -lt 10 ] && pp=" ${port}" || pp=${port}
|
||||
c=0; spc=''; spc1=`expr 28 - ${#PORT_DESC[${p}]}`; until [ ${c} = ${spc1} ]; do spc="${spc} "; c=`expr ${c} + 1`; done
|
||||
echo -e "${pp}) ${idsCL[LightCyan]}${PORT_DESC[${p}]}${spc}${idsCL[Default]}: ${portpower_disp}${idsCL[Default]}"
|
||||
done
|
||||
echo -e ""
|
||||
echo -e ""
|
||||
echo -e "(${idsCL[Yellow]}E${idsCL[Default]})xit"
|
||||
echo -e ""
|
||||
echo -e "\033[5A"
|
||||
# until [ "${PORTSEL}" != "" ]; do
|
||||
echo -en "\n${idsCL[LightCyan]}Enter the port number to control: ${idsCL[Default]}"
|
||||
read PORTSEL
|
||||
echo
|
||||
# done
|
||||
fi
|
||||
|
||||
[ "${PORTSEL^^}" == "E" ] && exit 0
|
||||
|
||||
if [ "${PORTSEL}" != "" ]; then
|
||||
portsel_power=$(snmpwalk -t 1 -r 0 -v 1 -c public ${PW_APCPDU_IP} .1.3.6.1.4.1.318.1.1.12.3.3.1.1.4.${PORTSEL} -O vq 2> /dev/null | sed -e 's/"//g')
|
||||
[ ${portsel_power} -eq 1 ] && portsel_power_disp="${idsCL[Green]}ON" || portsel_power_disp="${idsCL[LightRed]}OFF"
|
||||
[ ${portsel_power} -eq 2 ] && portsel_change_power_disp="${idsCL[Green]}ON" || portsel_change_power_disp="${idsCL[LightRed]}OFF"
|
||||
|
||||
portdesc=$(snmpwalk -t 1 -r 0 -v 1 -c public ${PW_APCPDU_IP} .1.3.6.1.4.1.318.1.1.12.3.3.1.1.2.${PORTSEL} -O vq 2> /dev/null | sed -e 's/"//g')
|
||||
DIVIDER . yellow 60
|
||||
echo -e "${idsCL[Yellow]}Port ${idsCL[LightYellow]}${PORTSEL}${idsCL[Default]}) ${idsCL[LightCyan]}${portdesc} ${idsCL[Default]}: ${portsel_power_disp}${idsCL[Default]}\n"
|
||||
|
||||
echo -en "${idsCL[LightCyan]}Are you sure you wish to turn ${portsel_change_power_disp}${idsCL[LightCyan]} port ${idsCL[Yellow]}${PORTSEL}${idsCL[Default]} (y/N): "
|
||||
read -n 1 portchange_confirm
|
||||
case "${portchange_confirm}" in
|
||||
[Yy])
|
||||
[ ${portsel_power} -eq 1 ] && portsel_change=2 || portsel_change=1
|
||||
echo -en "\n\n${idsCL[LightCyan]}Turning ${portsel_change_power_disp}${idsCL[LightCyan]} port ${idsCL[Yellow]}${PORTSEL}${idsCL[Default]} ... "
|
||||
run=$(snmpset -v 1 -c private ${PW_APCPDU_IP} .1.3.6.1.4.1.318.1.1.12.3.3.1.1.4.${PORTSEL} i ${portsel_change} >/dev/null 2>&1)
|
||||
echo -e "${idsCL[Green]}Done${idsCL[Default]}"
|
||||
until [ "${PORTSEL^^}" == "E" ]; do
|
||||
[ "${PORT_SEL}" != "" ] && PORTSEL=${PORT_SEL}
|
||||
if [ "${PORTSEL}" == "" ]; then
|
||||
PORT_DESC=$(snmpwalk -t 1 -r 0 -v 1 -c public ${PW_APCPDU_IP} .1.3.6.1.4.1.318.1.1.12.3.3.1.1.2 -O vq 2> /dev/null | sed -e 's/"//g')
|
||||
PORT_POWER=$(snmpwalk -t 1 -r 0 -v 1 -c public ${PW_APCPDU_IP} .1.3.6.1.4.1.318.1.1.12.3.3.1.1.4 -O vq 2> /dev/null | sed -e 's/"//g')
|
||||
IFS=$'\n'
|
||||
read -rd '' -a PORT_DESC <<<"${PORT_DESC}"
|
||||
read -rd '' -a PORT_POWER <<<"${PORT_POWER}"
|
||||
unset IFS
|
||||
for p in "${!PORT_DESC[@]}"; do
|
||||
port=$(expr ${p} + 1)
|
||||
[ ${PORT_POWER[${p}]} -eq 1 ] && portpower_disp="${idsCL[Green]}ON" || portpower_disp="${idsCL[LightRed]}OFF"
|
||||
[ ${port} -lt 10 ] && pp=" ${port}" || pp=${port}
|
||||
c=0; spc=''; spc1=`expr 28 - ${#PORT_DESC[${p}]}`; until [ ${c} = ${spc1} ]; do spc="${spc} "; c=`expr ${c} + 1`; done
|
||||
echo -e "${pp}) ${idsCL[LightCyan]}${PORT_DESC[${p}]}${spc}${idsCL[Default]}: ${portpower_disp}${idsCL[Default]}"
|
||||
done
|
||||
echo -e ""
|
||||
echo -e ""
|
||||
echo -e "(${idsCL[Yellow]}E${idsCL[Default]})xit"
|
||||
echo -e ""
|
||||
echo -e "\033[5A"
|
||||
# until [ "${PORTSEL}" != "" ]; do
|
||||
echo -en "\n${idsCL[LightCyan]}Enter the port number to control: ${idsCL[Default]}"
|
||||
read PORTSEL
|
||||
echo
|
||||
if [ "${PORT_SEL}" == "" ]; then
|
||||
sleep 1s
|
||||
unset PORTSEL
|
||||
PDUCONTROL
|
||||
exit 0
|
||||
fi
|
||||
;;
|
||||
*)
|
||||
if [ "${PORT_SEL}" == "" ]; then
|
||||
unset PORTSEL
|
||||
PDUCONTROL
|
||||
exit 0
|
||||
fi
|
||||
;;
|
||||
esac
|
||||
else
|
||||
if [ "${PORT_SEL}" == "" ]; then
|
||||
unset PORTSEL
|
||||
PDUCONTROL
|
||||
exit 0
|
||||
# done
|
||||
fi
|
||||
fi
|
||||
|
||||
[ "${PORTSEL^^}" == "E" ] && exit 0
|
||||
|
||||
if [ "${PORTSEL}" != "" ]; then
|
||||
portsel_power=$(snmpwalk -t 1 -r 0 -v 1 -c public ${PW_APCPDU_IP} .1.3.6.1.4.1.318.1.1.12.3.3.1.1.4.${PORTSEL} -O vq 2> /dev/null | sed -e 's/"//g')
|
||||
[ ${portsel_power} -eq 1 ] && portsel_power_disp="${idsCL[Green]}ON" || portsel_power_disp="${idsCL[LightRed]}OFF"
|
||||
[ ${portsel_power} -eq 2 ] && portsel_change_power_disp="${idsCL[Green]}ON" || portsel_change_power_disp="${idsCL[LightRed]}OFF"
|
||||
|
||||
portdesc=$(snmpwalk -t 1 -r 0 -v 1 -c public ${PW_APCPDU_IP} .1.3.6.1.4.1.318.1.1.12.3.3.1.1.2.${PORTSEL} -O vq 2> /dev/null | sed -e 's/"//g')
|
||||
DIVIDER . yellow 60
|
||||
echo -e "${idsCL[Yellow]}Port ${idsCL[LightYellow]}${PORTSEL}${idsCL[Default]}) ${idsCL[LightCyan]}${portdesc} ${idsCL[Default]}: ${portsel_power_disp}${idsCL[Default]}\n"
|
||||
|
||||
echo -en "${idsCL[LightCyan]}Are you sure you wish to turn ${portsel_change_power_disp}${idsCL[LightCyan]} port ${idsCL[Yellow]}${PORTSEL}${idsCL[Default]} (y/N): "
|
||||
read -n 1 portchange_confirm
|
||||
case "${portchange_confirm}" in
|
||||
[Yy])
|
||||
[ ${portsel_power} -eq 1 ] && portsel_change=2 || portsel_change=1
|
||||
echo -en "\n\n${idsCL[LightCyan]}Turning ${portsel_change_power_disp}${idsCL[LightCyan]} port ${idsCL[Yellow]}${PORTSEL}${idsCL[Default]} ... "
|
||||
run=$(snmpset -v 1 -c private ${PW_APCPDU_IP} .1.3.6.1.4.1.318.1.1.12.3.3.1.1.4.${PORTSEL} i ${portsel_change} >/dev/null 2>&1)
|
||||
echo -e "${idsCL[Green]}Done${idsCL[Default]}"
|
||||
echo
|
||||
# if [ "${PORT_SEL}" == "" ]; then
|
||||
# sleep 1s
|
||||
# unset PORTSEL
|
||||
# PDUCONTROL
|
||||
# exit 0
|
||||
# fi
|
||||
;;
|
||||
# *)
|
||||
# if [ "${PORT_SEL}" == "" ]; then
|
||||
# unset PORTSEL
|
||||
# PDUCONTROL
|
||||
# exit 0
|
||||
# fi
|
||||
# ;;
|
||||
esac
|
||||
|
||||
fi
|
||||
[ "${PORT_SEL}" != "" ] && exit 0 || echo
|
||||
done
|
||||
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user