Created
December 27, 2024 15:24
-
-
Save hackman/1711d0824a6335d7d843cb5aabc7a1b4 to your computer and use it in GitHub Desktop.
Manage the power outlets of old APC PDU
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| apc_url='http://192.168.2.82' | |
| auth='apc:apc' | |
| usage() { | |
| echo -e "Usage: $0 server on|off\nExample: $0 arista on\n" | |
| exit | |
| } | |
| if [[ $# -ne 2 ]]; then | |
| usage | |
| fi | |
| # Default command is off (cmd_id 4) | |
| cmd_id=4 | |
| port=3 | |
| if [[ $2 == "on" ]]; then | |
| cmd_id=2 | |
| fi | |
| # port 1 - 2.2 | |
| # port 2 - 3.2 | |
| # port 3 - 4.2 | |
| # port 4 - 5.2 | |
| # port 5 - 6.2 | |
| # port 6 - 7.2 | |
| # port 7 - 8.2 | |
| # port 8 - 9.2 | |
| # Resolve a name to port number | |
| case "$1" in | |
| switch) | |
| port=2 ;; | |
| arista) | |
| port=3 ;; | |
| pico) | |
| port=4 ;; | |
| badger) | |
| port=5 ;; | |
| durango) | |
| port=6 ;; | |
| gandalf) | |
| port=6 ;; | |
| pixie) | |
| port=7 ;; | |
| fay) | |
| port=8 ;; | |
| terion) | |
| port=9 ;; | |
| *) | |
| usage | |
| esac | |
| cmd_string="HX=&HX2=&C2=C2&rPDUOutletCtrl=$cmd_id&OL_Cntrl_Col1_Btn=%3F$port%2C2&Submit=Next+%3E%3E" | |
| # Login to the PDU and set the port to on or off | |
| curl -i -u $auth -X POST -d "$cmd_string" $apc_url/Forms/rPDUout1 | |
| # Now load the status screen and wait for 1sec. The wait is for the PDU to store the requested setting | |
| curl -i -u $auth http://192.168.2.82/rPDUoconf.htm > /dev/null 2>&1 | |
| sleep 1 | |
| # Apply the command | |
| curl -i -u $auth -X POST -d 'HX=&HX2=&C2=C2&Control=&Submit=Apply' $apc_url/Forms/rPDUoconf1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment