On 11/1/2012 7:24 PM, Vagrant Cascadian wrote:
On Wed, Oct 31, 2012 at 03:28:04PM -0400, John Hupp wrote:
For a Lubuntu LTSP network powered by a UPS, during a power outage I want to
notify all users in all X sessions with a popup message saying that the system
is running on battery and about to be shut down.
...
I imagine that there is already a developed method for handling a job like
that, using either notify-send or something else. Can anyone point the way?
You could start something from /etc/X11/Xsession.d/ that runs in the
background and waits for the presence of a file, and if the file is present,
displays the contents of the file. Drop something like this in
/etc/X11/Xsession.d/60-notify-of-ups-shutdown:
check_and_notify(){
# Sleep for 10 seconds
while sleep 10 ; do
# check for file...
if [ -f /var/run/ups-shutdown ]; then
# Display file to user.
xmessage -file /var/run/ups-shutdown
return $?
fi
done
}
check_and_notify &
And then your UPS monitoring software should write something to
/var/run/ups-shutdown...
There's probably a more elegant way, but hopefully that helps as a simple proof
of concept.
live well,
vagrant
MANY THANKS FOR THAT IDEA!! It was the heart of a solution for me.
One bit of troubleshooting with the above: My message was only
displaying once. Ididn't dig hard enoughto find out what the "$?"
argument of "return $?" was supposed to accomplish, but I read that
"return" causes an exitof the function. Removing the "return" allowed
the message to display periodically.
I also used notify-send instead of xmessage because, even though it was
not installed by default in my distro (Lubuntu), it seemed more
appropriate for notifications than xmessage, which is geared for user
input. Notify-send is installed by the package libnotify-bin.
My UPS monitortrigger: An apcupsd custom annoyme script (a script named
annoyme, placed in /etc/apcupsd)which creates a flag file named
ups-shutdown:
#!/bin/sh
if [ -f /var/run/ups-shutdown ]
then
echo -n ""
else
touch /var/run/ups-shutdown
fi
exit 0
A script which I named 60custom_notify-of-ups-shutdown (follows a
special naming convention for the Xsession.d folder, and the initial 60,
as you had it, places the script in a good position for alphabetical
execution), and which is placed in /etc/X11/Xsession.d:
check_and_notify()
{
# Sleep for 30 seconds. The sleep command always returns "true."
while sleep 30
do
# Check if file ups-shutdown exists. Buffer spaces within
brackets are required.
# The contents of the directory /var/run are deleted with each
bootup
# ";" simply allows running more than one command on a single line
if [ -f /var/run/ups-shutdown ]; then
# Display message to X session user
notify-send -t 5000 "The computer is running on battery."
"It will shut down shortly. Please save your work and log off."
fi
done
}
# The "&" suffix causes the command (the check_and_notify function)
to run in the background. Required not to stall the system.
check_and_notify &
For other newbies like me: The above script includes some non-executable
comment lines prefixed with #. Those lines could be removed. But the
initial #!/bin/sh in the script above that is required -- it identifies
the script interpreter to be used. I think maybe the second script does
not require such a "shebang" because scripts in that directory are
assumed to use the Bourne shell interpreter.
-----------------------------------
I also started to look at a relevant part of Alkis Georgopoulis' Epoptes
code at
https://bazaar.launchpad.net/~epoptes/epoptes/trunk/view/head:/epoptes-client/get-display
<https://bazaar.launchpad.net/%7Eepoptes/epoptes/trunk/view/head:/epoptes-client/get-display>,
but it seemed like I would have had to learn much more about scripting
just to understand the given script, apart from what more I would have
to do to adapt it for my solution. But perhaps someone else will know
enough about that to develop it as an alternative solution.
------------------------------------------------------------------------------
LogMeIn Central: Instant, anywhere, Remote PC access and management.
Stay in control, update software, and manage PCs from one command center
Diagnose problems and improve visibility into emerging IT issues
Automate, monitor and manage. Do more in less time with Central
http://p.sf.net/sfu/logmein12331_d2d
_____________________________________________________________________
Ltsp-discuss mailing list. To un-subscribe, or change prefs, goto:
https://lists.sourceforge.net/lists/listinfo/ltsp-discuss
For additional LTSP help, try #ltsp channel on irc.freenode.net