On Mon, 06 Feb 2017, Fraser_Bell wrote:
On 02/05/2017 01:38 PM, Michael Hamilton wrote:
I was looking for an answer to this quite recently, but found nothing inspiring, your question prompted me to revisit the issue.
There is an old question at stackexchange that addresses this issue:
http://unix.stackexchange.com/questions/2881/show-a-notification-across-all-...
None of the answers are truly satisfactory as there seems to be no universally correct, simple, standard, guaranteed equivalent to tty wall for X11. However, I did manage to get a modified solution to one of the suggestions to work on my system when run as root:
--- snip --- #!/bin/bash PATH=/usr/bin
XUSERS=($(who|egrep "\(:[0-9](\.[0-9])*\)"|awk '{print $1$NF}'|sort -u)) for XUSER in $XUSERS; do NAME=(${XUSER/(/ }) DISPLAY=${NAME[1]/)/} sudo -u ${NAME[0]} DISPLAY=${DISPLAY} \ notify-send "$@" done --- snip ---
If saved in notify-send-all, you can then do:
notify-send-all -i 'dialog-information' Warning 'Shutting down shortly.'
I haven't tested this with more than one display running and I haven't tested on anything other than KDE.
It does raise a question in my mind: if there is something bad in the logs, such as smartd deciding a disk is failing, will the GUI user be informed? Anyone know how this is handled in OpenSUSE?
Cheers, Michael
Thanks, Michael, I will test it out, but I am not sure what to expect.
I have tested with notify-send, xmessage, Wall, and at the time I am writing this I do not know what others I have tried before I wrote the original posting, but so far none work as expected and none send a pop-up note of any type in front of someone in the GUI.
They will only get the message if they happen to be working in the terminal at the time, and even then might not spot it.
Someone earlier mentioned they have tested Wall and it works: Well, it does *not* pop up a message or notification into the GUI, only to terminals.
If you are in a terminal started within the GUI, you will get the message *in the terminal window*, but if the window is minimized, or you are not looking in the terminal at the time, you will see nothing.
If a reasonable window manager is running, notify-send as each user should work. But it's true that notify-send won't work if the desktop lacks a listener for the message. I had another go at a script and this time added an option to use xterm to popup the message. (Plus I re-coded the script to be less clever with bash because I wasn't convinced that the one I originally modified was totally clear or correct). ---- snip ---- #!/bin/bash # Example usage: notify-send-all Going on holiday on 10 minutes PATH=/usr/bin # Set this to use an xterm instead of send-notify USE_XTERM=1 who | awk '$NF ~ /^\(.*:[0-9]+(\.[0-9])*\)$/ {gsub(/[()]/,"", $NF); print $1, $NF}'|sort -u | while read username displayname do if [ $USE_XTERM ] then msg="$@" # run an xterm as the username to echo out the message sudo -u "$username" DISPLAY="$displayname" xterm -geometry "130x10+400+400" -title Warning -e "echo $msg; sleep 10000" & else sudo -u "$username" DISPLAY="$displayname" notify-send "$@" fi done ---- snip ---- bash -x notify-send-all the sky is falling in two minutes I used Xephyr to test more than one display and confirmed this works. Something like kdialog might also be used, but xterm is a lowest common denominator. It's not pleasing that this kind code is necessary. I guess no one has been that concerned about the corner cases. Most people have a sophisticated desktop all to themselves. A remaining problem is that If anyone gets a display running without getting a utmp entry, then who won't be able to report their existence. For example, I had to start an xterm in Xephyr to get a utmp entry before testing. Cheers, Michael -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org To contact the owner, e-mail: opensuse+owner@opensuse.org