Brand Logo
Help
  • Get started
  • Ask the Community
  • How-To & Best Practices
  • Contact Support
Login / Register
Help
  • Get started
  • Ask the Community
  • How-To & Best Practices
  • Contact Support
close
  • Community Home
  • Forums
    • By Topic
    • By Topic
      EcoStruxure Building
      • Field Devices Forum
      • SmartConnector Forum
      EcoStruxure Power & Grid
      • Gateways and Energy Servers
      • Metering & Power Quality
      APC UPS, Critical Power, Cooling and Racks
      • APC UPS Data Center & Enterprise Solutions Forum
      • APC UPS for Home and Office Forum
      EcoStruxure IT
      • EcoStruxure IT forum
      Remote Operations
      • EcoStruxure Geo SCADA Expert Forum
      • Remote Operations Forum
      Industrial Automation
      • Alliance System Integrators Forum
      • AVEVA Plant SCADA Forum
      • CPG Expert Forum DACH
      • EcoStruxure Automation Expert / IEC 61499 Forum
      • Fabrika ve Makina Otomasyonu Çözümleri
      • Harmony Control Customization Forum
      • Industrial Edge Computing Forum
      • Industry Automation and Control Forum
      • Korea Industrial Automation Forum
      • Machine Automation Forum
      • Modicon PAC Forum
      • PLC Club Indonesia
      Schneider Electric Wiser
      • Schneider Electric Wiser Forum
      Power Distribution IEC
      • Eldistribution & Fastighetsautomation
      • Elektrik Tasarım Dağıtım ve Uygulama Çözümleri
      • Paneelbouw & Energie Distributie
      • Power Distribution and Digital
      • Solutions for Motor Management
      • Specifiers Club ZA Forum
      • Електропроектанти България
      Power Distribution NEMA
      • Power Monitoring and Energy Automation NAM
      Power Distribution Software
      • EcoStruxure Power Design Forum
      • LayoutFAST User Group Forum
      Light and Room Control
      • SpaceLogic C-Bus Forum
      Solutions for your Business
      • Solutions for your Business Forum
      Support
      • Ask the Community
  • Knowledge Center
    • Building Automation Knowledge Base
    • Geo SCADA Knowledge Base
    • Industrial Automation How-to videos
    • Digital E-books
    • Success Stories Corner
  • Events & Webinars
    • All Events
    • Innovation Talks
    • Innovation Summit
    • Let's Exchange Series
    • Partner Success
    • Process Automation Talks
    • Technology Partners
  • Ideas
    • EcoStruxure Building
      • EcoStruxure Building Advisor Ideas
      Remote Operations
      • EcoStruxure Geo SCADA Expert Ideas
      • Remote Operations Devices Ideas
      Industrial Automation
      • Modicon Ideas & new features
  • Blogs
    • By Topic
    • By Topic
      EcoStruxure Power & Grid
      • Backstage Access Resources
      Remote Operations
      • Remote Operations Blog
      Industrial Automation
      • Industrie du Futur France
      • Industry 4.0 Blog
      Power Distribution NEMA
      • NEMA Power Foundations Blog
      Light and Room Control
      • KNX Blog
      Knowledge Center
      • Digital E-books
      • Geo SCADA Knowledge Base
      • Industrial Automation How-to videos
      • Success Stories Corner

Automated scripting on Switched Rack PDU

APC UPS Data Center & Enterprise Solutions Forum

Schneider Electric support forum for our Data Center and Business Power UPS, UPS Accessories, Software, Services, and associated commercial products designed to share knowledge, installation, and configuration.

cancel
Turn on suggestions
Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.
Showing results for 
Show  only  | Search instead for 
Did you mean: 
  • Home
  • Communities
  • APC UPS, Critical Power, Cooling and Racks
  • APC UPS Data Center & Enterprise Solutions Forum
  • Automated scripting on Switched Rack PDU
Options
  • Subscribe to RSS Feed
  • Mark Topic as New
  • Mark Topic as Read
  • Float this Topic for Current User
  • Bookmark
  • Subscribe
  • Mute
  • Printer Friendly Page
Invite a Co-worker
Send a co-worker an invite to the Exchange portal.Just enter their email address and we’ll connect them to register. After joining, they will belong to the same company.
You have entered an invalid email address. Please re-enter the email address.
This co-worker has already been invited to the Exchange portal. Please invite another co-worker.
Please enter email address
Send Invite Cancel
Invitation Sent
Your invitation was sent.Thanks for sharing Exchange with your co-worker.
Send New Invite Close
Top Experts
User Count
BillP
Administrator BillP Administrator
5022
voidstar_apc
Janeway voidstar_apc
195
Erasmus_apc
Sisko Erasmus_apc
111
TheNotoriousKMP_apc
Sisko TheNotoriousKMP_apc
108
View All
Invite a Colleague

Found this content useful? Share it with a Colleague!

Invite a Colleague Invite
Solved Go to Solution
Back to APC UPS Data Center & Enterprise Solutions Forum
Solved
pedriyoo_apc
Crewman pedriyoo_apc
Crewman

Posted: ‎2021-06-28 06:22 AM

0 Likes
6
1917
  • Mark as New
  • Bookmark
  • Subscribe
  • Mute
  • Subscribe to RSS Feed
  • Permalink
  • Print
  • Email to a Friend
  • Report Inappropriate Content
Share

Posted: ‎2021-06-28 06:22 AM

Automated scripting on Switched Rack PDU

This was originally posted on APC forums on 2/9/2012


Hello all,

I am programming a little bash script that checks whether a machine is down or not, and if yes, it reboots the machine.

For doing so, it needs to connect to the PDU and launch the "reboot" command on the outlet to which the machine is connected.

The problem is that I want this to be automated but the ssh (and telnet) connection keeps asking me for the password... Isn't it possible to install a key certificate so that password is not required during my script execution?

I've read the manual but I can't figure out how to run automated scripts on the PDU.
Any ideas on this?

Thanks in advanced!!
Pedro

Labels
  • Labels:
  • Racks, Rack Accessories, & Cooling
  • Tags:
  • pdu
  • script
  • scripting
  • ssh
  • telnet
Reply
Share
  • All forum topics
  • Previous Topic
  • Next Topic

Accepted Solutions
pedriyoo_apc
Crewman pedriyoo_apc
Crewman

Posted: ‎2021-06-28 06:22 AM

1 Like
1
1913
  • Mark as New
  • Bookmark
  • Subscribe
  • Mute
  • Subscribe to RSS Feed
  • Permalink
  • Print
  • Email to a Friend
  • Report Inappropriate Content
Share

Posted: ‎2021-06-28 06:22 AM

This was originally posted on APC forums on 2/13/2012


Hi,
After some trial and error, and a few coffees too, I've managed to program a simple script that does what I mentioned.

Unfortunately, a UNIX tool called "expect" is needed, which is not installed by default in all UNIX-based distribution. You can install it via apt-get or yum (depending on your distribution)

The script basically waits until a string similar to the pattern given to "expect" is written on the console prompt, and then it sends the passwords (or commands) as if they were written by the user. The script works both for telnet and ssh2 connections (can't guarantee ssh1 since my workstation hasn't got it installed).

The code is the following:

// USE ---> /ssh_command.sh user password ip

// set Variables
set user [lrange $argv 0 0]
set password [lrange $argv 1 1]
set ipaddr [lrange $argv 2 2]
set timeout -1

// now connect to remote PDU
// using TELNET---> spawn telnet $ipaddr
spawn ssh $user@$ipaddr
match_max 100000

// Using TELNET
//expect "User Name :"
//send "$user"

// Look for passwod prompt
expect "*?assword*"
// Send password aka $password
send "$password"
expect "APC>"

send "off 1"
expect "APC>"

sleep 3

send "on 1"
expect "APC>"

send "exit"

expect eof
close $spawn_id

I hope this helps anyone with the same problem.

PS:
I tried to change the fingerprint of the PDU, but that didn't work because the fingerprint identifies the PDU so when other clients connect to it, they can trust this host (the PDU). However, the PDU wasn't able to recognize clients.

Tried also to upload the fingerprint of my workstation to a directory in the PDU (specifically "~/.ssh" as it says this tutorial), but the ftp server that runs on the PDU isn't very flexible, and doesn't allow you to create folders or so.

Message was edited by: pedriyoo

Message was edited by: pedriyoo

See Answer In Context

Reply
Share
Replies 6
BillP
Administrator BillP Administrator
Administrator

Posted: ‎2021-06-28 06:22 AM

0 Likes
0
1913
  • Mark as New
  • Bookmark
  • Subscribe
  • Mute
  • Subscribe to RSS Feed
  • Permalink
  • Print
  • Email to a Friend
  • Report Inappropriate Content
Share

Posted: ‎2021-06-28 06:22 AM

This reply was originally posted by Angela on APC forums on 2/9/2012


what model PDU is it? There is a scriping CLI on our two generations of PDUs outlined here: http://nam-en.apc.com/app/answers/detail/a_id/10853

Reply
Share
pedriyoo_apc
Crewman pedriyoo_apc
Crewman

Posted: ‎2021-06-28 06:22 AM

0 Likes
0
1913
  • Mark as New
  • Bookmark
  • Subscribe
  • Mute
  • Subscribe to RSS Feed
  • Permalink
  • Print
  • Email to a Friend
  • Report Inappropriate Content
Share

Posted: ‎2021-06-28 06:22 AM

This was originally posted on APC forums on 2/9/2012


It is a AP7920 device.

I can connect to the command line, but I'd like to connect to it using a certificate, so I can make an ssh connection in a script automatically, without giving out the password.

Reply
Share
BillP
Administrator BillP Administrator
Administrator

Posted: ‎2021-06-28 06:22 AM

0 Likes
0
1913
  • Mark as New
  • Bookmark
  • Subscribe
  • Mute
  • Subscribe to RSS Feed
  • Permalink
  • Print
  • Email to a Friend
  • Report Inappropriate Content
Share

Posted: ‎2021-06-28 06:22 AM

This reply was originally posted by Angela on APC forums on 2/9/2012


what SSH client are you using? i would think you could put the key in its keystore but i guess i have never tried. i am not sure if there is a way to get around typing the password completely 😕

Reply
Share
pedriyoo_apc
Crewman pedriyoo_apc
Crewman

Posted: ‎2021-06-28 06:22 AM

1 Like
1
1914
  • Mark as New
  • Bookmark
  • Subscribe
  • Mute
  • Subscribe to RSS Feed
  • Permalink
  • Print
  • Email to a Friend
  • Report Inappropriate Content
Share

Posted: ‎2021-06-28 06:22 AM

This was originally posted on APC forums on 2/13/2012


Hi,
After some trial and error, and a few coffees too, I've managed to program a simple script that does what I mentioned.

Unfortunately, a UNIX tool called "expect" is needed, which is not installed by default in all UNIX-based distribution. You can install it via apt-get or yum (depending on your distribution)

The script basically waits until a string similar to the pattern given to "expect" is written on the console prompt, and then it sends the passwords (or commands) as if they were written by the user. The script works both for telnet and ssh2 connections (can't guarantee ssh1 since my workstation hasn't got it installed).

The code is the following:

// USE ---> /ssh_command.sh user password ip

// set Variables
set user [lrange $argv 0 0]
set password [lrange $argv 1 1]
set ipaddr [lrange $argv 2 2]
set timeout -1

// now connect to remote PDU
// using TELNET---> spawn telnet $ipaddr
spawn ssh $user@$ipaddr
match_max 100000

// Using TELNET
//expect "User Name :"
//send "$user"

// Look for passwod prompt
expect "*?assword*"
// Send password aka $password
send "$password"
expect "APC>"

send "off 1"
expect "APC>"

sleep 3

send "on 1"
expect "APC>"

send "exit"

expect eof
close $spawn_id

I hope this helps anyone with the same problem.

PS:
I tried to change the fingerprint of the PDU, but that didn't work because the fingerprint identifies the PDU so when other clients connect to it, they can trust this host (the PDU). However, the PDU wasn't able to recognize clients.

Tried also to upload the fingerprint of my workstation to a directory in the PDU (specifically "~/.ssh" as it says this tutorial), but the ftp server that runs on the PDU isn't very flexible, and doesn't allow you to create folders or so.

Message was edited by: pedriyoo

Message was edited by: pedriyoo

Reply
Share
smallfish01
Crewman smallfish01
Crewman

Posted: ‎2022-04-28 11:17 PM

In response to pedriyoo_apc
0 Likes
0
1450
  • Mark as New
  • Bookmark
  • Subscribe
  • Mute
  • Subscribe to RSS Feed
  • Permalink
  • Print
  • Email to a Friend
  • Report Inappropriate Content
Share

Posted: ‎2022-04-28 11:17 PM

Hello,

 

Thanks for your provided the script, I have tried and found when I running the script ssh to PDU, but hung when I running the script.

 

# ./apc.sh apc apc 192.168.1.7

spawn ssh apc@192.168.1.7
apc@192.168.1.7's password: apc

 

Do you know the reason?

 

Thank you.

  • Tags:
  • english
Reply
Share
MyElectrons
Crewman MyElectrons
Crewman

Posted: ‎2022-08-16 06:55 PM

0 Likes
0
968
  • Mark as New
  • Bookmark
  • Subscribe
  • Mute
  • Subscribe to RSS Feed
  • Permalink
  • Print
  • Email to a Friend
  • Report Inappropriate Content
Share

Posted: ‎2022-08-16 06:55 PM

Hello to all happy APC Switched and Metered PDU owners and admins! 🙂

 

Last weekend I needed to automate outlet switching in my home lab. Here's what I've got for ap7901 & ap7902 PDUs:

https://github.com/MyElectrons/PDU-Commander

 

A sample command, executed from bash command line or a script:

./pdu-commander.py -a 192.168.7.242 -u device -p goodpassword on:1-2,8 delay:3 off:2 get:power

 

Script's output:

Address: 192.168.7.242
Unit ID: ap7902
Outlets: 16
('on', '1-2,8')
1: Outlet 1       : Outlet Turned On
2: Outlet 2       : Outlet Turned On
8: Outlet 8       : Outlet Turned On
('delay', '3')
('off', '2')
2: Outlet 2       : Outlet Turned Off
('get', 'power')
168 VA
168 Watts

 

There's logging, error handling, and a big potential for growth in that little project.

New features, improvement suggestions, and pull requests are very welcome!

 

Cheers,

 - Serge

  • Tags:
  • ap7900
  • ap7901
  • ap7902
  • cli
  • english
  • pdu
  • python
  • script
Reply
Share
Preview Exit Preview

never-displayed

You must be signed in to add attachments

never-displayed

Additional options
You do not have permission to remove this product association.
 
To The Top!

Forums

  • APC UPS Data Center Backup Solutions
  • EcoStruxure IT
  • EcoStruxure Geo SCADA Expert
  • Metering & Power Quality
  • Schneider Electric Wiser

Knowledge Center

Events & webinars

Ideas

Blogs

Get Started

  • Ask the Community
  • Community Guidelines
  • Community User Guide
  • How-To & Best Practice
  • Experts Leaderboard
  • Contact Support
Brand-Logo
Subscribing is a smart move!
You can subscribe to this forum after you log in or create your free account.
Forum-Icon

Create your free account or log in to subscribe to the forum - and gain access to more than 10,000+ support articles along with insights from experts and peers.

Register today for FREE

Register Now

Already have an account?Login

Terms & Conditions Privacy Notice Change your Cookie Settings © 2023 Schneider Electric, Inc