Is it possible to use notify-send to send messages to other users on the system?
preferably to a specified user, but system wide would work aswell.
Ubuntu/Debian with libnotify installed
Is it possible to use notify-send to send messages to other users on the system?
preferably to a specified user, but system wide would work aswell.
Ubuntu/Debian with libnotify installed
If you have the other users password you can do sudo -u somedude notify-send Hello
. somedude must have an X-session started.
Edit: Found this script for use with cron:
#!/bin/bash
PATH=/usr/local/bin:/usr/bin:/bin:/usr/X11R6/bin
export DISPLAY=:0.0
export $(grep -z DBUS_SESSION_BUS_ADDRESS /proc/$(pgrep -session)/environ )
TIME=$1
shift
/usr/bin/notify-send -t 36000 $1 $2
pgrep
is supposed to be getting the pid of the X-session manager, i.e. lxde-session, gnome-session etc. That script is a crude hack at best and depends a lot on your system setup. It worked when I answered but doesn't work without modification now, 5 years later.
If the users are on terminals the following commands will be of use -
write user [tty]
or to send to all users
wall
I stumbled upon the following project that implements a user notify: tinynotify-send
I needed similar tool to send notification to all sessions. Here is my solution: https://unix.stackexchange.com/a/230062/93227
It scans /proc to find all session busses and then it executes notify-send on each of it (once per bus). All arguments are passed unchanged to real notify-send.
#!/bin/bash
/bin/grep -sozZe '^DBUS_SESSION_BUS_ADDRESS=[a-zA-Z0-9:=,/-]*$' /proc/*/environ \
| /usr/bin/php -r '
$busses = array();
array_shift($argv);
while($ln = fgets(STDIN)) {
list($f, $env) = explode("\0", $ln, 2);
if (file_exists($f)) {
$user = fileowner($f);
$busses[$user][trim($env)] = true;
}
}
foreach ($busses as $user => $user_busses) {
foreach ($user_busses as $env => $true) {
if (pcntl_fork()) {
posix_seteuid($user);
$env_array = array("DBUS_SESSION_BUS_ADDRESS" => preg_replace("/^DBUS_SESSION_BUS_ADDRESS=/", "", $env));
pcntl_exec("/usr/bin/notify-send", $argv, $env_array);
}
}
}
' -- "$@"