Skip to content

Instantly share code, notes, and snippets.

@jerapiblaze
Created June 17, 2025 05:18
Show Gist options
  • Save jerapiblaze/211f83700042aa4f41150939292ba6c1 to your computer and use it in GitHub Desktop.
Save jerapiblaze/211f83700042aa4f41150939292ba6c1 to your computer and use it in GitHub Desktop.
A script to send broadcast message to all terminals and desktop sessions.
#!/bin/bash
# notify-send-all
PATH=/usr/bin:/bin
send-to() {
local name busroute
name="$1"; shift
busroute="/run/user/$(id -u "$name")/bus" || return 1
sudo -u "$name" \
PATH="$PATH" \
DBUS_SESSION_BUS_ADDRESS="unix:path=$busroute" \
-- \
notify-send "$@" 2>&1 | sed "s/^/$name\t/"
}
send-all() {
for name in $(who | cut -f1 -d" " | sort -u)
do
send-to "$name" "$@" &
done
wait
}
broadcast() {
wall "$1
$2"
send-all $1 $2 -u critical -a "From sysadmin" -e
}
sudo --validate
broadcast "$@"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment