Sie befinden sich hier: Krischer.org » Linux » Shorties » bash » Notify User on root scripts

Notify User on root scripts

With kdialog and notify-send it is pretty easy to send yourself a message to your desktop eviroment via dbus.

It gets more complicated if you run a script as root and did not have the authority to use the users dbus by design.

The following function sends every user on a the machine a notification and can be used easily in your own scripts. Tested on openSUSE 11.1.

notify_me() {
  ALL_USER="$(users | sort)"
  echo Desktop-Message to: $ALL_USER
        for USER_TMP in $ALL_USER; do
                if [ "$USER_TMP" = "$USER_LAST" ]; then
                        #if user already notified, continue
                        continue
                fi
                su $USER_TMP -c "XAUTHORITY=/home/$USER_TMP/.Xauthority DISPLAY=:0 notify-send $1 $2"
                #save last username to avoid double notification
                USER_LAST=$USER_TMP
        done
}

The Usage is pretty simple, although I had to figuring out the Syntax:

 notify_me '"HEADLINE"' '"MESSAGETEXT"'
 
Nach oben
linux/shorties/bash/desktop_notification.txt · Zuletzt geändert: 2009/11/17 01:04 von Manuel Krischer
edv-krischer.de Valid CSS Driven by DokuWiki Recent changes RSS feed Valid XHTML 1.0