Created
June 17, 2025 05:18
-
-
Save jerapiblaze/211f83700042aa4f41150939292ba6c1 to your computer and use it in GitHub Desktop.
A script to send broadcast message to all terminals and desktop sessions.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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