Help
  • Explore Community
  • Get Started
  • Ask the Community
  • How-To & Best Practices
  • Contact Support
Notifications
Login / Register
Community
Community
Notifications
close
  • Forums
  • Knowledge Center
  • Events & Webinars
  • Ideas
  • Blogs
Help
Help
  • Explore Community
  • Get Started
  • Ask the Community
  • How-To & Best Practices
  • Contact Support
Login / Register
Sustainability
Sustainability

We Value Your Feedback!
Could you please spare a few minutes to share your thoughts on Cloud Connected vs On-Premise Services. Your feedback can help us shape the future of services.
Learn more about the survey or Click here to Launch the survey
Schneider Electric Services Innovation Team!

Automated scripting on Switched Rack PDU

APC UPS Data Center & Enterprise Solutions Forum

Schneider, APC support forum to share knowledge about installation and configuration for Data Center and Business Power UPSs, Accessories, Software, Services.

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
  • Schneider Electric Community
  • APC UPS, Critical Power, Cooling and Racks
  • APC UPS Data Center & Enterprise Solutions Forum
  • Automated scripting on Switched Rack PDU
Options
  • 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 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
5060
voidstar_apc
Janeway voidstar_apc
196
Teken
Spock Teken
113
Erasmus_apc
Sisko Erasmus_apc
112
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
Anonymous user
Not applicable

Posted: β€Ž2021-06-28 06:22 AM . Last Modified: β€Ž2024-03-18 02:26 AM

0 Likes
6
6476
  • Mark as New
  • Bookmark
  • Subscribe
  • Mute
  • Permalink
  • Print
  • Email to a Friend
  • Report Inappropriate Content

Link copied. Please paste this link to share this article on your social media post.

Posted: β€Ž2021-06-28 06:22 AM . Last Modified: β€Ž2024-03-18 02:26 AM

Automated scripting on Switched Rack PDU

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
Contact Support

Link copied. Please paste this link to share this article on your social media post.

  • All forum topics
  • Previous Topic
  • Next Topic

Accepted Solutions
Anonymous user
Not applicable

Posted: β€Ž2021-06-28 06:22 AM . Last Modified: β€Ž2024-03-18 02:25 AM

1 Like
1
6472
  • Mark as New
  • Bookmark
  • Subscribe
  • Mute
  • Permalink
  • Print
  • Email to a Friend
  • Report Inappropriate Content

Link copied. Please paste this link to share this article on your social media post.

Posted: β€Ž2021-06-28 06:22 AM . Last Modified: β€Ž2024-03-18 02:25 AM

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
Contact Support

Link copied. Please paste this link to share this article on your social media post.

Replies 6
BillP
Administrator BillP Administrator
Administrator

Posted: β€Ž2021-06-28 06:22 AM . Last Modified: β€Ž2025-05-30 12:30 AM

0 Likes
0
6472
  • Mark as New
  • Bookmark
  • Subscribe
  • Mute
  • Permalink
  • Print
  • Email to a Friend
  • Report Inappropriate Content

Link copied. Please paste this link to share this article on your social media post.

Posted: β€Ž2021-06-28 06:22 AM . Last Modified: β€Ž2025-05-30 12:30 AM

what model PDU is it? There is a scriping CLI on our two generations of PDUs outlined 

Reply
Contact Support

Link copied. Please paste this link to share this article on your social media post.

Anonymous user
Not applicable

Posted: β€Ž2021-06-28 06:22 AM . Last Modified: β€Ž2024-03-18 02:25 AM

0 Likes
0
6472
  • Mark as New
  • Bookmark
  • Subscribe
  • Mute
  • Permalink
  • Print
  • Email to a Friend
  • Report Inappropriate Content

Link copied. Please paste this link to share this article on your social media post.

Posted: β€Ž2021-06-28 06:22 AM . Last Modified: β€Ž2024-03-18 02:25 AM

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
Contact Support

Link copied. Please paste this link to share this article on your social media post.

BillP
Administrator BillP Administrator
Administrator

Posted: β€Ž2021-06-28 06:22 AM . Last Modified: β€Ž2024-03-18 02:25 AM

0 Likes
0
6472
  • Mark as New
  • Bookmark
  • Subscribe
  • Mute
  • Permalink
  • Print
  • Email to a Friend
  • Report Inappropriate Content

Link copied. Please paste this link to share this article on your social media post.

Posted: β€Ž2021-06-28 06:22 AM . Last Modified: β€Ž2024-03-18 02:25 AM

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
Contact Support

Link copied. Please paste this link to share this article on your social media post.

Anonymous user
Not applicable

Posted: β€Ž2021-06-28 06:22 AM . Last Modified: β€Ž2024-03-18 02:25 AM

1 Like
1
6473
  • Mark as New
  • Bookmark
  • Subscribe
  • Mute
  • Permalink
  • Print
  • Email to a Friend
  • Report Inappropriate Content

Link copied. Please paste this link to share this article on your social media post.

Posted: β€Ž2021-06-28 06:22 AM . Last Modified: β€Ž2024-03-18 02:25 AM

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
Contact Support

Link copied. Please paste this link to share this article on your social media post.

smallfish01
Crewman smallfish01
Crewman

Posted: β€Ž2022-04-28 11:17 PM

In response to Anonymous user
0 Likes
0
6009
  • Mark as New
  • Bookmark
  • Subscribe
  • Mute
  • Permalink
  • Print
  • Email to a Friend
  • Report Inappropriate Content

Link copied. Please paste this link to share this article on your social media post.

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
Contact Support

Link copied. Please paste this link to share this article on your social media post.

MyElectrons
Crewman MyElectrons
Crewman

Posted: β€Ž2022-08-16 06:55 PM

0 Likes
0
5527
  • Mark as New
  • Bookmark
  • Subscribe
  • Mute
  • Permalink
  • Print
  • Email to a Friend
  • Report Inappropriate Content

Link copied. Please paste this link to share this article on your social media post.

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
Contact Support

Link copied. Please paste this link to share this article on your social media post.

Preview Exit Preview

never-displayed

You must be signed in to add attachments

never-displayed

Β 
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 board after you log in or create your free account.
Forum-Icon

Create your free account or log in to subscribe to the board - 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 Β© 2025 Schneider Electric

This is a heading

With achievable small steps, users progress and continually feel satisfaction in task accomplishment.

Usetiful Onboarding Checklist remembers the progress of every user, allowing them to take bite-sized journeys and continue where they left.

of