Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
notify-send as root
View unanswered posts
View posts from last 24 hours
View posts from last 7 days

 
Reply to topic    Gentoo Forums Forum Index Desktop Environments
View previous topic :: View next topic  
Author Message
seVes
n00b
n00b


Joined: 06 Jan 2011
Posts: 54
Location: Germany

PostPosted: Mon Apr 15, 2013 4:37 am    Post subject: notify-send as root Reply with quote

hey guys,

i've some understanding-problems with notify-send and root.

let me explain:

i wrote a custom automount-script for udev, which only automount devices with specific id.
the rule is executed properly and the given script too.

in that script i want to make a bubble-notify to the user. the user is "alex" (its me :D). X runs as alex. udev is running as root in boot-runlevel.

i found out, that this is a mistake by xauthority xcookie or something like that. i also tried to use sux or sudo but it doesnt work within the script.
except the script, by using a root-terminal in X it works. something is wrong but i dont know how to fix this.

automount.sh
Code:
...
# for example, these variables are set:
#  ICON="drive-removable-media-usb2"
#  TYPE="USB stick"
#  LABEL="my sexy usbstick"
#  MNTPOINT="/media/usbstick"
...
notify-send -u low -i ${ICON} "${TYPE}" "Status:\t\tmounted\nLabel:\t\t${LABEL}\nMountpoint:\t${MNTPOINT}"' alex
...

thanks for helping me to fix this. +1
kind regards
_________________
Alex / seVes
Back to top
View user's profile Send private message
amospalla
n00b
n00b


Joined: 08 Mar 2013
Posts: 26

PostPosted: Mon Apr 15, 2013 9:41 am    Post subject: Reply with quote

$ emerge x11-misc/tinynotify-send-1.2.1 x11-misc/sw-notify-send

(mask tinynotify-send-1.2.1-r1 which has dependency problems)

then execute :
$ tinynotify-send -w message


Last edited by amospalla on Mon Apr 15, 2013 11:08 am; edited 1 time in total
Back to top
View user's profile Send private message
ppurka
Advocate
Advocate


Joined: 26 Dec 2004
Posts: 3256

PostPosted: Mon Apr 15, 2013 11:02 am    Post subject: Reply with quote

You can try three things, in succession (i.e., do 2. after you have tried out 1., but don't remove the modification of 1.) and see which one gives you the desired result.

1. Export the DISPLAY variable in your automount script. Like
Code:
export DISPLAY=":0.0"


2. Run the notify-send as the user alex by running it through su. Like
Code:
su alex -c "your command"
Since it is run as root, there is no need to give the password.

3. If 2. doesn't work, then try to export the DBUS_SESSION_BUS_ADDRESS variable from the user's dbus session. You can also try to make the notification into a separate script that is run completely by the user alex. The code below tries to do this, assuming that the script is being run by alex.
Code:
#!/usr/bin/env bash
cd "$HOME/.dbus/session-bus"
dbus_file="$( ls -t1 | head -n 1 )"
export DBUS_SESSION_BUS_ADDRESS="$( source "$dbus_file"; echo $DBUS_SESSION_BUS_ADDRESS )"
export DISPLAY=":0.0"
notify-send ....
And you can call this script, let's say it is called notify_user, from inside automount.sh by running it as the user
Code:
#from automount.sh
su alex -c "/path/to/notify_user $MOUNT_POINT ..."


The third part is the most elaborate and might be needed if 1, and 2 fails to show you the notification. Given how cryptic all the *kits are, you might need this part 3.
_________________
emerge --quiet redefined | E17 vids: I, II | Now using kde5 | e is unstable :-/
Back to top
View user's profile Send private message
seVes
n00b
n00b


Joined: 06 Jan 2011
Posts: 54
Location: Germany

PostPosted: Mon Apr 15, 2013 1:53 pm    Post subject: Reply with quote

Thanks ppurka, 1 + 2 works perfectly for me.

Nice shoot! :-) Thank you very much, for sure! +1
_________________
Alex / seVes
Back to top
View user's profile Send private message
SamuliSuominen
Retired Dev
Retired Dev


Joined: 30 Sep 2005
Posts: 2133
Location: Finland

PostPosted: Mon Apr 15, 2013 4:15 pm    Post subject: Reply with quote

amospalla wrote:
$ emerge x11-misc/tinynotify-send-1.2.1 x11-misc/sw-notify-send

(mask tinynotify-send-1.2.1-r1 which has dependency problems)

then execute :
$ tinynotify-send -w message


You are solving the dependency problem wrong. You should NOT be masking 1.2.1-r1, or use 1.2.1. I'll remove 1.2.1 from tree to prevent others from making the same mistake.

Opened https://bugs.gentoo.org/466004 which will make it easier to install, but for now you can simply add all of...

Quote:

~x11-libs/libnotify-0.7.5
=app-admin/eselect-notify-send-0*
~x11-misc/tinynotify-send-1.2.1
~x11-misc/sw-notify-send-1.2.1


...to /etc/portage/package.keywords
Back to top
View user's profile Send private message
amospalla
n00b
n00b


Joined: 08 Mar 2013
Posts: 26

PostPosted: Mon Apr 15, 2013 4:56 pm    Post subject: Reply with quote

Thank you ssuominen, have it working with that.
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Desktop Environments All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum