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.
Posted: 2021-06-30 01:59 AM . Last Modified: 2024-03-11 12:18 AM
Link copied. Please paste this link to share this article on your social media post.
Posted: 2021-06-30 01:59 AM . Last Modified: 2024-03-11 12:18 AM
Hello,
I am newbie when it comes to PowerChute Network Shutdown and how it works with how I setup my UPS Network Management Card 2, I am hoping someone can help shed some light.
I would like to display a message to inform the user that the computer will shut down. I read that an email could be send but I would like to a terminal which open to display a message or an alert box (like "notify-send" on Linux).
I tried on the web interface of PowerChute Network Shutdown:
Configure Events --> Notification
Where I put the IP address of my computer, but it didn’t work.
So I tried:
Configure Events --> Command File
Where I write a script in bash. In my script, I used the command “notify-send” to display an alert box. It didn’t work too.
So I tried:
Shutdown Settings --> run Command
Where I put the same script as before. It didn’t work too.
So I tried:
Shutdown Setting --> Notify Users but it didn’t work too
After I am gone to on the web interface of my UPS Network Management Card 2 and I tried:
Configuration --> Notification --> Event Action
But I haven’t of notification.
Has anyone ever had this problem?
If you have ideas, I'll take them.
Thanks in advance to anyone that responds to this post.
Marie
Link copied. Please paste this link to share this article on your social media post.
Posted: 2021-06-30 02:01 AM . Last Modified: 2024-03-11 12:17 AM
Link copied. Please paste this link to share this article on your social media post.
Posted: 2021-06-30 02:01 AM . Last Modified: 2024-03-11 12:17 AM
Hi voidstar
I thank you for your answer and I apologize for answering only now. I have not had the time to test your proposed solution but I hope to do it next week.
I inform you for the result.
Marie
Link copied. Please paste this link to share this article on your social media post.
Link copied. Please paste this link to share this article on your social media post.
Posted: 2021-06-30 02:00 AM . Last Modified: 2024-03-11 12:18 AM
Hi,
On a Windows system PowerChute will post to the screen.
The notification last around 60 seconds prior to shutdown.
On a Linux system you can write a script to send notification. If you need assistance with scripting syntax see Schneider Electric FAQ FA159559
Link copied. Please paste this link to share this article on your social media post.
Posted: 2021-06-30 02:00 AM . Last Modified: 2024-03-11 12:18 AM
Link copied. Please paste this link to share this article on your social media post.
Posted: 2021-06-30 02:00 AM . Last Modified: 2024-03-11 12:18 AM
Hi,
I thank you for your answer.
My script on Linux is:
#!/bin/sh
notify-send ‘message error’ ‘The computer will shut down’
sleep 15
I put on the command file et run Command but it didn’t work. I read Schneider Electric FAQ FA159559 but I don’t understand why it didn’t work. Can you help me please? Do I have a fault on my script?
Link copied. Please paste this link to share this article on your social media post.
Link copied. Please paste this link to share this article on your social media post.
Posted: 2021-06-30 02:00 AM . Last Modified: 2024-03-11 12:18 AM
By default notify-send delivers a notification to the user who runs it. In your case that's PowerChute, not the other users logged into the machine. I see a variety of solutions posted on the web for notifying all users... for example:
I imagine there's going to be challenges with permissions also. If I were you, I'd test sending a notification using a separate account, not the one logged into the display server.
Link copied. Please paste this link to share this article on your social media post.
Posted: 2021-06-30 02:00 AM . Last Modified: 2024-03-11 12:18 AM
Link copied. Please paste this link to share this article on your social media post.
Posted: 2021-06-30 02:00 AM . Last Modified: 2024-03-11 12:18 AM
Hi,
I thank you for your answer voidstar.
I read your exemple and I tried solutions like:
#!/bin/sh
DISPLAY=:0 sudo –u user_display_0 notify-send “The computer will shut down”
The code works on the terminal. I put the script in “Command File” of "UPS On Battery" in “Configure Events” of PowerChute and it doesn’t work.
Is there a fault in my script? Or I do not use the right step?
Marie
Link copied. Please paste this link to share this article on your social media post.
Link copied. Please paste this link to share this article on your social media post.
Posted: 2021-06-30 02:00 AM . Last Modified: 2024-03-11 12:18 AM
That uses sudo to perform "notify-send" as a particular user. But "sudo" is locked down. Here's what happens when I try to run it as another user:
voidstar@starbase3:~$ su test
test@starbase3:~$ DISPLAY=:0 sudo -u voidstar notify-send "test 1.. 2.. 3..."
[sudo] password for test:
test is not in the sudoers file. This incident will be reported.
So, the first problem is it asks for a password interactively, so that's not going to work from PowerChute. The second problem is my test user is not in the sudoers file. When I fix all of those, it still doesn't work.
I got the third answer (mivk) to work. Of course we're both running Ubuntu 16.04. I shortened his script to:
#!/bin/bash
title="Computer Shutting Down"
msg="We're shutting down now"
who | awk '{print $1, $NF}' | tr -d "()" |
while read u d; do
id=$(id -u $u)
. /run/user/$id/dbus-session
export DBUS_SESSION_BUS_ADDRESS
export DISPLAY=$d
su $u -c "/usr/bin/notify-send '$title' '$msg'"
done
Made sure my user was in the sudoers file, and ran the script above using "sudo" to make sure it had the privilege to connect to everyone's DBUS session.
Linux really needs a better standard way to do this.
Link copied. Please paste this link to share this article on your social media post.
Posted: 2021-06-30 02:00 AM . Last Modified: 2024-03-11 12:18 AM
Link copied. Please paste this link to share this article on your social media post.
Posted: 2021-06-30 02:00 AM . Last Modified: 2024-03-11 12:18 AM
Hi,
I don’t understand this line :
. /run/user/$id/dbus-session
What does it mean?
Marie
Link copied. Please paste this link to share this article on your social media post.
Link copied. Please paste this link to share this article on your social media post.
Posted: 2021-06-30 02:00 AM . Last Modified: 2024-03-11 12:18 AM
Hi Marie,
The dbus-session file contains the bus address for the particular user. It's in a form that can be directly executed by a shell script:
DBUS_SESSION_BUS_ADDRESS=unix:abstract=/tmp/dbus-kji3ADFKWI
The "." command runs the dbus-session file which causes the variable DBUS_SESSION_BUS_ADDRESS to become bound to the bus address. In the next line we export the variable to the environment so that notify-send uses it.
Link copied. Please paste this link to share this article on your social media post.
Posted: 2021-06-30 02:00 AM . Last Modified: 2024-03-11 12:18 AM
Link copied. Please paste this link to share this article on your social media post.
Posted: 2021-06-30 02:00 AM . Last Modified: 2024-03-11 12:18 AM
Hi voidsta,
I thank you for your answer.
I tried your solutions but I have error message “/run/user/503/dbus-session : No such file or directory.
I checked and I haven’t the file /run/user. What does the /run/user file contain?
Marie
Link copied. Please paste this link to share this article on your social media post.
Link copied. Please paste this link to share this article on your social media post.
Posted: 2021-06-30 02:01 AM . Last Modified: 2024-03-11 12:17 AM
I guess it's probably distro-specific. I'm using Ubuntu 16.04 LTS; which distro are you using? Perhaps we can find a system-wide notification solution for your distro.
Link copied. Please paste this link to share this article on your social media post.
Posted: 2021-06-30 02:01 AM . Last Modified: 2024-03-11 12:17 AM
Link copied. Please paste this link to share this article on your social media post.
Posted: 2021-06-30 02:01 AM . Last Modified: 2024-03-11 12:17 AM
Hi,
I have Linux version 2.6.32-358 (gcc version 4.4.7 20120313 (Red Hat 4.4.7-3) (GCC)).
Marie
Link copied. Please paste this link to share this article on your social media post.
Link copied. Please paste this link to share this article on your social media post.
Posted: 2021-06-30 02:01 AM . Last Modified: 2024-03-11 12:17 AM
Hi Marie,
I looked around and didn't see anything specific to Red Hat Enterprise Linux 4. I did find this (replace X_user and X_userid with the username and user id respectively):
sudo -u X_user DISPLAY=:0 DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/X_userid/bus notify-send 'Hello world!' 'This is an example notification.'
I don't know if it'll work for you but it's worth a shot.
Link copied. Please paste this link to share this article on your social media post.
Posted: 2021-06-30 02:01 AM . Last Modified: 2024-03-11 12:17 AM
Link copied. Please paste this link to share this article on your social media post.
Posted: 2021-06-30 02:01 AM . Last Modified: 2024-03-11 12:17 AM
Hi voidstar
I thank you for your answer and I apologize for answering only now. I have not had the time to test your proposed solution but I hope to do it next week.
I inform you for the result.
Marie
Link copied. Please paste this link to share this article on your social media post.
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.