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
|
DIVIDER . yellow 75
|
||||||
echo -e "${idsCL[Yellow]}APC-PDU Power Control"
|
echo -e "${idsCL[Yellow]}APC-PDU Power Control"
|
||||||
DIVIDER true yellow 75
|
DIVIDER true yellow 75
|
||||||
[ "${PORT_SEL}" != "" ] && PORTSEL=${PORT_SEL}
|
until [ "${PORTSEL^^}" == "E" ]; do
|
||||||
if [ "${PORTSEL}" == "" ]; then
|
[ "${PORT_SEL}" != "" ] && PORTSEL=${PORT_SEL}
|
||||||
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')
|
if [ "${PORTSEL}" == "" ]; then
|
||||||
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')
|
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')
|
||||||
IFS=$'\n'
|
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')
|
||||||
read -rd '' -a PORT_DESC <<<"${PORT_DESC}"
|
IFS=$'\n'
|
||||||
read -rd '' -a PORT_POWER <<<"${PORT_POWER}"
|
read -rd '' -a PORT_DESC <<<"${PORT_DESC}"
|
||||||
unset IFS
|
read -rd '' -a PORT_POWER <<<"${PORT_POWER}"
|
||||||
for p in "${!PORT_DESC[@]}"; do
|
unset IFS
|
||||||
port=$(expr ${p} + 1)
|
for p in "${!PORT_DESC[@]}"; do
|
||||||
[ ${PORT_POWER[${p}]} -eq 1 ] && portpower_disp="${idsCL[Green]}ON" || portpower_disp="${idsCL[LightRed]}OFF"
|
port=$(expr ${p} + 1)
|
||||||
[ ${port} -lt 10 ] && pp=" ${port}" || pp=${port}
|
[ ${PORT_POWER[${p}]} -eq 1 ] && portpower_disp="${idsCL[Green]}ON" || portpower_disp="${idsCL[LightRed]}OFF"
|
||||||
c=0; spc=''; spc1=`expr 28 - ${#PORT_DESC[${p}]}`; until [ ${c} = ${spc1} ]; do spc="${spc} "; c=`expr ${c} + 1`; done
|
[ ${port} -lt 10 ] && pp=" ${port}" || pp=${port}
|
||||||
echo -e "${pp}) ${idsCL[LightCyan]}${PORT_DESC[${p}]}${spc}${idsCL[Default]}: ${portpower_disp}${idsCL[Default]}"
|
c=0; spc=''; spc1=`expr 28 - ${#PORT_DESC[${p}]}`; until [ ${c} = ${spc1} ]; do spc="${spc} "; c=`expr ${c} + 1`; done
|
||||||
done
|
echo -e "${pp}) ${idsCL[LightCyan]}${PORT_DESC[${p}]}${spc}${idsCL[Default]}: ${portpower_disp}${idsCL[Default]}"
|
||||||
echo -e ""
|
done
|
||||||
echo -e ""
|
echo -e ""
|
||||||
echo -e "(${idsCL[Yellow]}E${idsCL[Default]})xit"
|
echo -e ""
|
||||||
echo -e ""
|
echo -e "(${idsCL[Yellow]}E${idsCL[Default]})xit"
|
||||||
echo -e "\033[5A"
|
echo -e ""
|
||||||
# until [ "${PORTSEL}" != "" ]; do
|
echo -e "\033[5A"
|
||||||
echo -en "\n${idsCL[LightCyan]}Enter the port number to control: ${idsCL[Default]}"
|
# until [ "${PORTSEL}" != "" ]; do
|
||||||
read PORTSEL
|
echo -en "\n${idsCL[LightCyan]}Enter the port number to control: ${idsCL[Default]}"
|
||||||
echo
|
read PORTSEL
|
||||||
# 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]}"
|
|
||||||
echo
|
echo
|
||||||
if [ "${PORT_SEL}" == "" ]; then
|
# done
|
||||||
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
|
|
||||||
fi
|
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