From c6ab2b9b0dbe1cb013550d53344e581c1bc86f25 Mon Sep 17 00:00:00 2001 From: David Schroeder Date: Fri, 12 Jan 2024 19:33:42 -0600 Subject: [PATCH] Update power.inc.sh --- inc/power.inc.sh | 63 +++++++++++++++++++++++++++--------------------- 1 file changed, 35 insertions(+), 28 deletions(-) diff --git a/inc/power.inc.sh b/inc/power.inc.sh index ffd9c945..ab4e6c38 100644 --- a/inc/power.inc.sh +++ b/inc/power.inc.sh @@ -889,40 +889,47 @@ PDUCONTROL(){ [ "${PORTSEL^^}" == "E" ] && exit 0 - 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" - 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 + else + if [ "${PORT_SEL}" == "" ]; then + unset PORTSEL + PDUCONTROL + exit 0 + fi fi - 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 } SENDPOWER(){