0

Please help. We are trying to write some automation for several CyberPower PDUs in our datacenter. They are rack mount switched PDUs (PDU41002) and they have the ability to be remotely managed, however we are having trouble with some of the code. The PDU is accessible via SSH and when manually logged in via the console, we can successfully control the outlets. We are trying to script this using remote SSH commands. We can successfully SSH from another linux server and will be again prompted with the interactive menu, however, if we instead just try to send SSH commands to interact with the menu, we get error messages. The problem seems to be tied to this proprietary interactive console menu. When you login, thats all you get. You dont get a normal terminal prompt. Just the menu. It looks as follows:

CyberPowerSystems Inc., Command Shell v1.0

CyberPower System                        ePDU Firmware Version    1.0.8
(c) Copyright 2010 All Rights Reserved   PDU41002
+------- Information -------------------------------------------------------+
Name     : 10.10.10.2                    Date : 2019/01/02
Contact  : Administrator                 Time : 01:58:40
Location : Datacenter                    User : Administrator
Up Time  : 108 days 22 hours 38 mins 39 secs.
+------- Console -----------------------------------------------------------+

     1- Device Manager
     2- Network Settings
     3- System
     4- Logout

      <ESC>- Back, <ENTER>- Select&Reflash
> 4

Here is what we get if we just try to remote SSH. Notice, we have to force an older encryption to get it to work. This works, just not the goal. ie we are able to successfully login from our testing Linux box via the console and once inside the PDU are presented with the normal interactive console menu.

administrator@10.10.10.1:~$ ssh -c aes128-cbc,3des-cbc administrator@10.10.10.2
password:
CyberPowerSystems Inc., Command Shell v1.0

CyberPower System                        ePDU Firmware Version    1.0.8
(c) Copyright 2010 All Rights Reserved   PDU41002
+------- Information -------------------------------------------------------+
Name     : 10.10.10.2                    Date : 2019/01/02
Contact  : Administrator                 Time : 01:58:40
Location : Datacenter                    User : Administrator
Up Time  : 108 days 22 hours 38 mins 39 secs.
+------- Console -----------------------------------------------------------+

     1- Device Manager
     2- Network Settings
     3- System
     4- Logout

      <ESC>- Back, <ENTER>- Select&Reflash
>

If however, we try to specify some command, we get the following:

administrator@10.10.10.1:~$ ssh -c aes128-cbc,3des-cbc administrator@10.10.10.2 "1"
password:
exec request failed on channel 0

Any thoughts?

* SOLUTION *

In case anyone out there comes across this post and needs to get something like this working for the same PDU, here is the working script. I made it as basic as possible. You just pass the hostname username password and outlet and hit go:

#!/usr/bin/expect -f
set hostname [lindex $argv 0]
set username [lindex $argv 1]
set password [lindex $argv 2]
set outlet [lindex $argv 3]
spawn ssh -c aes128-cbc,3des-cbc $username@$hostname
expect "password: "
send "$password\r"
expect "> "
send "1\r"
expect "> "
send "2\r"
expect "> "
send "1\r"
expect "> "
send "$outlet\r"
expect "> "
send "6\r"
expect "> "
send "yes\r"
expect "> "

As an example, to power cycle outlet 3 (perhaps a hung server), you would enter the following. This assumes you have named your script example.sh and set it to executable:

./<script> <hostname or IP> <username> <password> <outlet>

./example.sh 10.10.10.2 administrator secretpass 3

Hope this helps someone else out there!

2

Use expect or one of the many alternative implementations. It's meant for exactly this case. It will wait for a specific prompt and then send the configured response like an interactive session.

  • Looking that up now. Can you expand on that though? Thanks! – Atomiklan Jan 1 at 19:10
  • Testing it now! – Atomiklan Jan 1 at 19:14
  • Looks like this is going to work fantastic! Thank you! Few more tweaks, but the first attempt script was 90% successful. Testing again. – Atomiklan Jan 1 at 19:19
  • Glad it helped. – Sven Jan 1 at 19:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.