LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Slackware
User Name
Password
Slackware This Forum is for the discussion of Slackware Linux.

Notices


Reply
  Search this Thread
Old 10-14-2012, 05:40 AM   #1
markush
Senior Member
 
Registered: Apr 2007
Location: Germany
Distribution: Slackware
Posts: 3,979

Rep: Reputation: Disabled
udev and dbus - using the notivy-send command in a script started by udev


Hello together,

I'm lost with this issue. Referring to this thread I've written an udev-rule which recognizes the plugin of an USB-memory-stick and calls a script which mounts the device. So far so good.

Here's the script:
Code:
#!/bin/bash

# USB-Stick mounten
sleep 5
device=`dmesg | grep -e sd.: | tail -n 1 | sed -n 's/.*sd.:\s\+\?\(.*\)/\1/i p'`
name=`dmesg | grep -i product: | tail -n 1 | sed -n 's/.*product:\s\+\(.*\)/\1/i p' | sed -n 's/\ /_/g p'`


if [ ! -d /media/$name ]; then 
				mkdir /media/$name
fi
mount /dev/$device /media/$name
#for LINE in $(find /proc/ -maxdepth 2 -name environ -exec grep -z "^DBUS_SESSION_BUS_ADDRESS" {} \; | sort -uz | tr '\0' '\n') 
#do 
#				eval $LINE
#done
#username=`who | head -n 1 | cut -d " " -f 1`
#su $username -c notify-send "USB-Speicherstick eingehängt auf /media/$name" 
echo "USB-Speicherstick eingehaengt auf /media/$name" | wall
Additionally I want to receive a message about where the device is mounted.

I've tried the "notify-send" command which works when I call the script on the commandline (as root as well as a normal user). The problem is that the message is not shown when the script is called from udev. I searched the internet and found that the problem is with dbus. What I have understood is that the script, when called from udev doesn't know where to display the message. The reason is that the script needs additional information about a (some?) variables from dbus. There are solutions explained in several places in the internet, but I did not understand one of them.

Does anyone know which variable (information from dbus) the notify-send command needs and which way I can provide this information to the command. There's no manpage vor notify-send and the helptext for the command doesn't provide as much information. As you can see in the script I've tried out various ideas. using "su -c username" doesn't work, and I did not understand what to do with DBUS_SESSION_BUS_ADDRESS.

I've also found udev-notify at slackbuilds.org, but could not find out if an how this tool could help me.

Markus
 
Old 10-14-2012, 07:23 AM   #2
phenixia2003
Senior Member
 
Registered: May 2006
Location: France
Distribution: Slackware
Posts: 1,052

Rep: Reputation: 1008Reputation: 1008Reputation: 1008Reputation: 1008Reputation: 1008Reputation: 1008Reputation: 1008Reputation: 1008
Hello,

I encountered the same kind of problem when I wanted to add a notification mechanism to compat32pkg. I fixed that problem
by exporting the variable DISPLAY. So, in your case, you should simply have to change your code as below:

Code:
export DISPLAY=:0.0 su $username -c notify-send "USB-Speicherstick eingehängt auf /media/$name"
Greetings.

--
SeB
 
1 members found this post helpful.
Old 10-14-2012, 09:26 AM   #3
markush
Senior Member
 
Registered: Apr 2007
Location: Germany
Distribution: Slackware
Posts: 3,979

Original Poster
Rep: Reputation: Disabled
Thanks very much to phenixia2003, I've got it working now, here's the script:
Code:
#!/bin/bash                                                                                                                                                            
                                                                                                                                                                       
# USB-Stick mounten                                                                                                                                                    
sleep 5                                                                                                                                                                
device=`dmesg | grep -e sd.: | tail -n 1 | sed -n 's/.*sd.:\s\+\?\(.*\)/\1/i p'`                                                                                       
name=`dmesg | grep -i product: | tail -n 1 | sed -n 's/.*product:\s\+\(.*\)/\1/i p' | sed -n 's/\ /_/g p'`                                                             
                                                                                                                                                                       
if [ ! -d /media/$name ]; then                                                                                                                                         
    mkdir /media/$name                                                                                                                                                 
fi                                                                                                                                                                     
mount /dev/$device /media/$name                                                                                                                                        
username=`who | head -n 1 | cut -d " " -f 1`                                                                                                                           
export DISPLAY=:0.0                                                                                                                                                    
su $username -c "notify-send 'USB-Speicherstick eingehaengt auf /media/$name'"
The " and ' musst be where they are because otherwise the $name-variable isn't correctly evaluated.

Markus
 
  


Reply

Tags
dbus, udev



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Udev started twice at start-up?!? rawrFox Slackware 3 02-21-2012 11:42 PM
UDEV: Unable to run a command line interface script after USB automount using udev mohamr2 Linux - Embedded & Single-board computer 8 08-16-2011 10:39 AM
script command works unless started by udev kscott121 Linux - Software 2 12-31-2007 10:38 PM
udev, hotplug, hal, dbus : implementation HowDoIProgramIt Linux - Hardware 2 08-16-2007 07:48 PM
4-in1 Card Reader, HAL, dbus, and/or udev marnold Slackware 5 07-14-2007 11:13 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Slackware

All times are GMT -5. The time now is 05:28 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration