Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- ########################################################################################################
- # #
- # This program is free software: you can redistribute it and/or modify #
- # it under the terms of the GNU General Public License as published by #
- # the Free Software Foundation, either version 3 of the License, or #
- # (at your option) any later version. #
- # #
- # This program is distributed in the hope that it will be useful, #
- # but WITHOUT ANY WARRANTY; without even the implied warranty of #
- # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
- # GNU General Public License for more details. #
- # #
- # You should have received a copy of the GNU General Public License #
- # along with this program. If not, see <http://www.gnu.org/licenses/>. #
- # #
- # Bash-Script to send broadcasts to all users to the desktop-notification-daemon (via notify-send). #
- # root permissions are required to call notify-send from another users account (sudo -u $user). #
- # #
- # Written in bash using getopts for options processing. #
- # Type "notify-send-wall -h" to get usage Information. #
- # #
- ########################################################################################################
- sessionarray="openbox" # i.e. "gnome-session openbox startkde"
- [ "x$DISPLAY" = "x" ] && export DISPLAY=:0.0
- # Defaults
- title="No Title"
- timeout="2000" # message-timeout in milliseconds (only with notification-daemon or modified notify-osd)
- icon="foo.bar"
- urgency="normal"
- # Process options with getopts
- while getopts ":t:m:i:T:u:vh" opt; do
- case $opt in
- t) title=$OPTARG;; # setting title, else fall back to "no title"
- m) message=$OPTARG;; # message text (optional)
- T) timeout=$OPTARG;; # display-time in milliseconds (optional)
- i) icon=$OPTARG;; # notification icon (optional), could be i.e. "battery", "sonata", "network" or an icon path.
- u) urgency=$OPTARG;; # notification urgency-level, default= normal
- v) echo -e "notify-send-wall: Written in bash, using getopts. Made by Henning Hollermann 2011/10, GPL v3 License."; exit 0;;
- h) echo -e "Usage: $0 -t <title> [options]\nOptions:\n -t <title>\tSet Title\n -m <msg>\tSet Message to Display\n -T <time>\tSet Display-Time in milliseconds (default: 2000ms)\n -i\t\tNotification icon. Could be something like battery-charging, sonata, network or an icon file path. \n -u\t\tSet urgency-level of message (low|normal|critical)\n -h\t\tDisplay this help message\n -v\t\tDisplay version information"; exit 0;;
- \?) echo -e "Invalid option: -$OPTARG\n$help" >&2; exit 1;;
- :) echo "Option -$OPTARG requires an argument." >&2; exit 1;;
- esac
- done
- # Send notification to all sessions
- for session in $sessionarray; do
- pids=$(pgrep $session)
- for pid in $pids; do
- # Determine session owner
- user=$(stat -c '%U' /proc/$pid)
- # send notification to session (must be executed by $user: root-permissions sequired)
- sudo -u $user DBUS_SESSION_BUS_ADDRESS=$(grep -z DBUS_SESSION_BUS_ADDRESS /proc/$pid/environ | sed -e 's/DBUS_SESSION_BUS_ADDRESS=//') /usr/bin/notify-send -i "$icon" -u $urgency -t "$timeout" "$title" "$message"
- done;
- done
- # Logging
- #logger "sudo -u $user DBUS_SESSION_BUS_ADDRESS=$(grep -z DBUS_SESSION_BUS_ADDRESS /proc/$pid/environ | sed -e 's/DBUS_SESSION_BUS_ADDRESS=//') /usr/bin/notify-send -i "$icon" -u normal -t "$timeout" "$title" "$message""
- exit 0;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement