IP based Power Distribution Units (PDUs)

IP based Power Distribution Units (PDU) are a tool that allows an administrator to control the on/off status of devices via the network. These are invaluable when direct access to the devices is not possible and the device needs to be powered on/off.

Cmd line Ref DigiPower AMz-1623-SW-08-1 8 port Rack PDU, 16A 230V, IEC320 C20 Plug (7), C13 (1)
Cmd line Ref Aviosys IP Power 9258 SF 8 port desktop,15A 230V, IEC320 C20 Plug (4), French (4)
These devices offer remote control interfaces via HTTP, HTTPS and SNMP. The challenge with these devices is that each interface is different and they may or may not support a command line interface for automating device management.

As one of the networks I manage contained a mixture of these devices the challenge of automating control became very complex because of the differenct interfaces. To make this simpler I created a script library (bash) that standardises the interface so that the underlying complexity does not have to be dealt with. You can download this library from here. This was designed to work under any environment that supports bash and the GNU tool set (Linux, BSD, Cygwin etc).

The script supports two modes of operation, direct command line (params passed on command line of script) and calls to the embedded functions

  • Before you use it you will need to edit the section which defines the devices and change things like the IP address and passwords. If you do not have a particular device type then comment out

  • To test the functionality call the script as follows (direct mode):
    	/path/lib_msgcmdexec.sh test
      Which should display details of your PDUs
      Alternatively in script mode:
    	. /path/lib_msgcmdexec.sh
  • In your script you initialise the libary by calling (script mode):
    	. /path/lib_msgcmdexec.sh
  • Help can be found be calling:
    	. /path/lib_msgcmdexec.sh test help
  • To determine the settings of a port:
    	. /path/lib_msgcmdexec.sh test cmd_exec getpower P01
  • To turn a port on/off call:
    	. /path/lib_msgcmdexec.sh test cmd_exec setpower P01=1   (or =on)
    	. /path/lib_msgcmdexec.sh test cmd_exec setpower P01=off (or =0)
  • For more details of the commands supported you should look at the functions within the script and in particular at the case statement in the cmd_exec function.

    Note on security: In the original environment this runs on a system which has no users and controlled access, anyone which can call this script is authorised to access the PDUs and would have the passwords. For less secure environments the script supports the concept of RO/RW access via the use of the "auth" command, which can either prefix other commands or be sent separately. This functionality is overridden by default in the header of the script; if you require this authentication then comment out the line that reads sIPPWR_AUTH_OK="RW".

  • To use the auth function you would prefix a command with auth followed by the RO or RW password:
    	. /path/lib_msgcmdexec.sh test cmd_exec auth password setpower P01=1
  • A second function is the ability to read in the entire parameter section, either from the environment of the calling script or from a config script. If you use this functionality it is suggested that you exec the dumpvars function to create the file then delete all the lines between the sections marked with "# SOT #" and "# EOT #". The config file may exist in the same directory as the script or in the calling users home directory.

    Use at your own risk!.