how to show emergency pop up message to user? (on X)
Linux - GeneralThis Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
how to show emergency pop up message to user? (on X)
Hi there
I need a surefire way to inform a user logged in on a remote desktop on his X session (Gnome or KDE).
I have root access to his machine and log in remotely and have to be able to tell him that the file server is not available at the moment or such.
So far no luck, wall does only work for command line and is quite outdated in a time where people don't do their word processing in the CLI anymore.
It has to generate a pop up window in the X session of the user logged in on a computer or better ANY user logged in.
kdialog also does not work, since I cannot get it to display on the remote machine while logged in on SSH.
xhost + is really acting wierd since it is supposed to give all hosts access to the xserver of the remote machine and instead, it tries to open a X display, which it cannot (why is it doing that in the first place? xhost is a access restricting / granting program, not anything that opens or uses a x screen)
logger is a program that might work, it generates log messages for the system log, but I guess if you can generate a message of enough severity, it might (or must) pop up on the user screen, no matter in which way the person is logged in.
logger -p kern.emerg "this is urgent, act now"
unfortunately does not do a thing. A kernel emergency should trigger a pop up like that, shouldn't it?
Anyone know a severity of log entry that will get out on all channels available to a machine? I know that shutdown messages do and they have to do that somehow...
In a Freedesktop compliant desktop (gnome, kde), the service/usr/libexec/notification-daemon from notification-daemon package and the associated utility /usr/bin/notify-send from libnotify package (in a fedora8 distro) may be what you are looking for.
I use gnome and in a script that takes a long time to finish, I use this to notify me about the progress.
Code:
...
# a milestone has reached
/usr/bin/notify-send -t 0 "Results" "Phase 3 has completed."
...
# starting phase 4
...
as result, I got a small box on the right corner about the progress.
"/usr/bin/notify-send --help" to get details about the several options.
The box is the same the gnome uses to display several informational messages you may already seen.
shutdown unfortunately does not show any message. I was wrong about that, very strange. The user should know when the machine is shutting down.
This is on Ubuntu (with KDE), so it might be a Ubuntu bug.
You may tweak your syslog config file to create a new message type and bind it to a named pipe.
Then you need to create a script that receive input from that named pipe and output the message using notify-send, osd_cat, xmessage, whatever, on the user's X-display. This script runs with the user session and there is no xhost issues.
When you want to inform the user about anything, you can use logger as root or any other local user, with the appropriated message type and it will trigger your named pipe and output program.
Me: KDE 3.5.10, kubuntu 8.04.1, kernel 2.6.24-21-generic (& I love it!)
kdialog is nice, but will not send output to a screen that is owned by someone else.
For example, tred is on display :0 and user is on :1
Code:
tred@vaio:~$ kdialog --display :0 --msgbox "Test" It works
tred@vaio:~$ kdialog --display :1 --msgbox "Test"
No protocol specified
kdialog: cannot connect to X server :1
# OK, let's try it as the user "user" ....
tred@vaio:~$ su - user
Password:
user@vaio:~$ sleep 20; kdialog --display :1 --msgbox "Test"
# Press CTRL-ALT-F8 to switch to display :1, wait.... It works! Switch
# back to :0 with CTRL-ALT-F7
# Maybe root can do it .....
user@vaio:~$ exit
tred@vaio:~$ sudo -i
Password:
root@vaio:~# kdialog --display :1 --msgbox "Test2"
No protocol specified
kdialog: cannot connect to X server :1
root@vaio:~#
# Grrrrrrrr.
I am trying to find kubuntu's equivalent of /usr/bin/notify-send ...
Found it, it's in the package libnotify-bin
But:
Code:
tred@vaio:~$ /usr/bin/notify-send -t 0 "Results" "Phase 3 has completed."
libnotify-Message: Unable to get session bus: Failed to execute dbus-launch to autolaunch D-Bus session
tred@vaio:~$
What kind of error is that? dbus is running (but I don't have a dbus-launch executable in my path) I installed dbus-x11 and kdbus.
Now the command executes:
Code:
tred@vaio:~$ /usr/bin/notify-send -t 0 "Results" "Phase 3 has completed."
tred@vaio:~$
but nothing happens to the screen.
osdsh works the same way as kdialog; it won't send to a screen not owned by the invoker.
I am really surprised that the OP's Q (Which is, basically, "How do I notify all users, who are running X of something important, like an imminent reboot?") hasn't been answered yet. I will be very interested in the answer. There has to be one. Please?
There *is* a popup notification standard in the Freedesktop standard. However, so far as I have found, nobody has written a simple program to make use of it. The best I can find are Python bindings for the library...
But, if you wish a simple workaround, and you have root privileges on the machine in question, then it's pretty easy.
su -c "xhost +" <username> will disable authentication on whatever display <username> happens to be using. Then *anyone* can send graphical outputs to their screen. (So be sure to turn it back on with xhost - when you're done.)
After that, just use xmessage, zenity, or whatever other popup generator program you want. You can even dump the message to a file and open it in a graphical text editor if that suits your sense of style...
Yes, this is very interesting. And there must be an answer. I have not tried the last post before this one, but xhost + so far has given me hard trouble. It always tells me "cannot open display". xhost is not a graphical application, it does not use or open a display, it sets permissions. Is there a bug in there? Why does it tell me "cannot open display" when I use it with "give permission to all"?
Well, I am sure we will crack that nut and as life sometimes puts you the right things in the way, I am learning Python at the moment and love it.
So taking a look at these bindings will be fun.
But honestly: am I the only one that is very bothered by the stupid Xserver thing that root is powerless to influence users screens? Root can do ANYTHING, it does not need permission to use a screen, it should be all powerful about everything in the system.
One of the biggest bothers for me is that when I go
su -
on the CLI that then I cannot start GUI tools anymore, "cannot open display", without giving Root permission.
What sense does that make? None!
I love Linux for all the great things that it make so much sense in. Coming from Windows some long time ago, I am hardly getting upset, since things are well designed in Linux. In Windows, there is no end to stupidity in what Microsoft cooked up and how lame and inconsistent it is. The guys that designed / and still are designing Linux (and Unix before) really know what they are doing.
But in this case above, I fail to see it. I wish this could be changed, because it does really not serve any purpose. Being root must bring total power with it. Does anybody know a xhost statement that will enable root to use all displays? (but not everybody else, since xhost + is a aweful security hole)
I just wanted to tag this thread, seeing as I am in the same boat as everyone. I have an app that runs headless as root (it's a daemon service) that needs to output notifications to all users if something bad happens. I have tried everything above as well, and I was thinking there must be a way to tap into the notifications that pop up from the system? You know the ones that pop up from Aptitude or its equivalent in KDE.
This only works writing to a proper terminal - the <CTRL><ALT><F2> type.
You don't need to be root, but you must both have enabled messaging with mesg y beforehand.
It it will not pop up a message window if the other user is logged into a GUI and it will not write to an xterm window either.
@tlhonmey,
Your suggestion doesn't seem to work either:
Code:
tred@vaio:~$ who
testuser tty2 2008-12-07 12:36
tred :0 2008-12-07 09:25
testuser :1 2008-12-07 12:30
tred@vaio:~$ kdialog --display :0 --msgbox "Test" #It works, on my display which is :0
tred@vaio:~$ kdesu -c "xhost +"
access control disabled, clients can connect from any host
tred@vaio:~$ kdialog --display :1 --msgbox "Test" #Fails to work:
No protocol specified
kdialog: cannot connect to X server :1
tred@vaio:~$ kdesu -c "kdialog --display :1 --msgbox "Test""
No protocol specified
kdialog: cannot connect to X server :1
tred@vaio:~$ sudo -i
root@vaio:~# kdialog --display :1 --msgbox "Test" #Fails to work:
No protocol specified
kdialog: cannot connect to X server :1
root@vaio:~# xhost -
access control enabled, only authorized clients can connect
root@vaio:~# exit
tred@vaio:~$
But thanks for trying.
So it looks like this thread is still "not solved".
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.