LinuxQuestions.org
Visit Jeremy's Blog.
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
 
LinkBack Search this Thread
Old 10-11-2012, 08:27 AM   #1
markush
Senior Member
 
Registered: Apr 2007
Location: Germany
Distribution: Slackware
Posts: 3,970

Rep: Reputation: 848Reputation: 848Reputation: 848Reputation: 848Reputation: 848Reputation: 848Reputation: 848
Mounting USB-storage devices using udev-rules


Hello,

I've created an udev-rule
Code:
SUBSYSTEMS=="usb", KERNEL=="sd?1", SYMLINK+="usbstick", RUN+="/usr/local/bin/mount-usb.sh
which executes the following script:
Code:
#!/bin/bash

# USB-Stick mounten
device=`dmesg | tail -n 15 | grep -e sd.: | sed -n 's/.*sd.:\s\+\?\(.*\)/\1/i p'`
name=`dmesg | tail -n 15 | grep -i product: | 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

notify-send "USB-Speicherstick eingehängt auf /media/$name"
but the "notify-send" command only works when I execute the script manually as root. Why?

Also it seems that the script is too complicated. Is there another way to get the name of the device-node and the product-name of the device?

I want to unmount the device as a normal user. How can I do this?

Also I want to delete the directory in /media after unmounting the device, how can I do this? I consider to write a script which cleans /media when the system starts.
How did you solve this issues?

BTW: I don't use KDE or XFCE.

Markus
 
Old 10-11-2012, 12:08 PM   #2
Didier Spaier
Senior Member
 
Registered: Nov 2008
Location: Paris, France
Distribution: Slackware-14.0 on a Lenovo T61 6457-4XG
Posts: 3,638

Rep: Reputation: 827Reputation: 827Reputation: 827Reputation: 827Reputation: 827Reputation: 827Reputation: 827
Quote:
Originally Posted by markush View Post
Also it seems that the script is too complicated. Is there another way to get the name of the device-node and the product-name of the device?
lsusb or usb-devices
 
Old 10-11-2012, 12:20 PM   #3
markush
Senior Member
 
Registered: Apr 2007
Location: Germany
Distribution: Slackware
Posts: 3,970

Original Poster
Rep: Reputation: 848Reputation: 848Reputation: 848Reputation: 848Reputation: 848Reputation: 848Reputation: 848
Quote:
Originally Posted by Didier Spaier View Post
lsusb or usb-devices
Yes, I know this commands, but they don't show the devicenode.

Markus
 
Old 10-11-2012, 12:45 PM   #4
guanx
Senior Member
 
Registered: Dec 2008
Posts: 1,014

Rep: Reputation: 145Reputation: 145
Did you try "/dev/bus/usb/${BUSNUM}/${DEVNUM}"? Or simply use "set" to list all environment variables in your script to see which you'd like to use.
 
Old 10-11-2012, 12:59 PM   #5
markush
Senior Member
 
Registered: Apr 2007
Location: Germany
Distribution: Slackware
Posts: 3,970

Original Poster
Rep: Reputation: 848Reputation: 848Reputation: 848Reputation: 848Reputation: 848Reputation: 848Reputation: 848
Well, thanks for the answers, maybe I'm missing something. But the only place where I can see the path for the lastest connected USB-device is the output of dmesg.
I could compare the output of df and "ls /dev/sd*", this would show me which sd?? isn't yet mounted.

I found out that the "notify-send" command only works together with dbus. Now I'll try to find out how this works.

Markus
 
Old 10-11-2012, 01:35 PM   #6
markush
Senior Member
 
Registered: Apr 2007
Location: Germany
Distribution: Slackware
Posts: 3,970

Original Poster
Rep: Reputation: 848Reputation: 848Reputation: 848Reputation: 848Reputation: 848Reputation: 848Reputation: 848
I've changed 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                                                   
                                                                   
notify-send "USB-Speicherstick eingehängt auf /media/$name"
I've swaped the tail and grep commands. It works properly now.

As of "notify-send", when I do as root on the commandline "export $(dbus-launch)" and afterwards execute the script manually, the notification works. Unfortunately there seems to be no manpage for dbus, so I couldn't find out how to get this working.

Markus
 
Old 10-11-2012, 06:25 PM   #7
T3slider
Senior Member
 
Registered: Jul 2007
Distribution: Slackware64-14.0
Posts: 2,231

Rep: Reputation: 573Reputation: 573Reputation: 573Reputation: 573Reputation: 573Reputation: 573
I think the proper way to get the device name/information is to pass them as arguments in the udev rule. See `man udev` for some possible variables (eg. %k). I'm no udev expert and I don't have time right now to check what the proper arguments should be, but doing a
Code:
grep RUN /lib/udev/rules.d/*
should give you some examples of how it is done for other devices.
 
1 members found this post helpful.
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
VirtualBox USB devices history effect: fstab and udev rules catkin Slackware 3 11-07-2010 09:48 AM
slackware 12.0, udev rules for usb-dev works, but mounting does not work correct paalmarker Linux - General 5 03-30-2010 01:51 AM
Mounting USB storage devices COKE CAN Debian 18 08-02-2005 02:14 AM
mounting usb storage devices blues patitoconejita Linux - Hardware 7 03-29-2005 07:24 AM
Automatically Mounting USB Storage Devices??? nalmo Linux - General 6 08-13-2004 03:15 PM


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

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration