Created
September 14, 2018 11:28
-
-
Save Bonno/7bc048bb5f8f3493ea99b86abd4dde8e to your computer and use it in GitHub Desktop.
Send notification to all x users with notify-send
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
users=$(who | grep -iv pts | awk '{print $1}') | |
for user in $users | |
do | |
echo $user | |
pgrep "gnome-session" -u $user | while read -r line; do | |
#exp=$(cat /proc/$line/environ | grep -z "^DBUS_SESSION_BUS_ADDRESS=") | |
exp=$(grep -z DBUS_SESSION_BUS_ADDRESS /proc/$line/environ | tr '\0' '\n') | |
echo export "$exp" > /tmp/exports.sh | |
break | |
done | |
if [[ -f /tmp/exports.sh ]]; then | |
source /tmp/exports.sh | |
export DBUS_SESSION_BUS_ADDRESS | |
export DISPLAY=$d | |
su $user -c "/usr/bin/notify-send 'Hi!' 'test'" | |
rm /tmp/exports.sh | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment