I am re-approaching a question I first began chewing on in the thread "A script for shutting down an LTSP client from the host?"

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. My starting point is that the UPS management daemon runs a control script which will call my custom script named "annoyme," and will run that script as root.

I have been trying to do this with notify-send, but there is the inherent problem that when notify-send is run as root, there is no DBUS_SESSION_BUS_ADDRESS variable, and notify-send relies on that value to direct its output to the proper session.

There are some scripts that solve the problem for a given user name (see below), but I want to address all users in general. Somewhere along the line, I thought I saw such a script in passing, but now I can't find it.

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?

------------

And here is an example of a script that addresses one known user:

#!/bin/sh

init_notify() {
    user=`whoami`
    pids=`pgrep -u $user nautilus`
    for pid in $pids; do
        # find DBUS session bus for this session
DBUS_SESSION_BUS_ADDRESS=`grep -z DBUS_SESSION_BUS_ADDRESS /proc/$pid/environ | sed -e 's/DBUS_SESSION_BUS_ADDRESS=//'`
        # use it
        export DBUS_SESSION_BUS_ADDRESS=$DBUS_SESSION_BUS_ADDRESS
    done
}

notify() {
    if [ -z "$DBUS_SESSION_BUS_ADDRESS" ]; then
        init_notify
    fi

    title=$1
    text=$2
    timeout=$3

    if [ -z "$title" ]; then
        return
    fi
    if [ -z "$text" ]; then
        text=$title
    fi
    if [ -z "$timeout" ]; then
        timeout=5000
    fi

    notify-send "$title" "$text" -t $timeout
}

# Just copy&paste these two functions into your script and just type 'notify "title" "text" 5000' in your script where you want to send a notification. # Don't forget to write the correct username in the "init_notify()" function.



------------------------------------------------------------------------------
Everyone hates slow websites. So do we.
Make your web apps faster with AppDynamics
Download AppDynamics Lite for free today:
http://p.sf.net/sfu/appdyn_sfd2d_oct
_____________________________________________________________________
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

Reply via email to