Notifications from root via shell script
What is the proper way to send notifications to X terminals on Ubuntu 12.04 (Precise Pangolin)?
The notifications are used for the following:
ssh: Notification to the remote user that an administrator has connected so don't panic and pull the plug.
openvpn: Notification to the administrator that a remote client has connected to allow a return ssh session for administration through a restrictive firewall.
smartd: Notification of drive failures.
mdadm: Notification of RAID events.
I'm using Linux Mint 13 (maya) in a gnome-fallback session since my test hardware (i855GM Intel chipset) doesn't support usable 3D but I need this to work with any system with Cinnamon and Unity also.
On Ubuntu 10.04 (Lucid Lynx) I had to go tty hunting with ps then extract the DISPLAY variable from /proc/<
Note that I can't use ck-list-sessions as notifications need to be sent to the display manager if no users are logged in. The DM session does not show up in ck-list-sessions.
With 12.04, the DISPLAY variable is not in the environment of the process that is connected to the tty. I've worked around this by extracting the display setting in the X command line from ps args. Not robust but it's the least bad method I've found.
However, this isn't enough to get notify-send functioning. I figured out that DISPLAY has to be set, notification-daemon started for root, then notify-send used to send the message. This cycle has to be repeated for every X terminal.
In addition, there are timing bugs with this approach. I have to add in sleep between launching the daemon and sending the message else it doesn't work. Even then, the notification often disappears abruptly, long before the timeout expires. I had this problem with Lucid also but adding a short sleep before terminating the script solved the problem. It's worse on Precise as it occurs even if the script hasn't terminated.
In general, this makes the script unreliable and slow. Is there a better method available using D-bus or something?
Question information
- Language:
- English Edit question
- Status:
- Solved
- For:
- Ubuntu libnotify Edit question
- Assignee:
- No assignee Edit question
- Solved by:
- actionparsnip
- Solved:
- Last query:
- Last reply: