LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 02-11-2016, 02:14 PM   #1
Mikeoxlarge
LQ Newbie
 
Registered: Feb 2016
Posts: 4

Rep: Reputation: Disabled
Unhappy Getting UDEV working


Hey guys, first post here so go gentle

I've created a udev rule file in my udev/rules.d with the following contents,


Code:
ACTION=="add", SUBSYSTEM=="usb",  ATTRS{idVendor}=="18a5", ATTRS{idProduct}=="0302", RUN+="/etc/demo/insert.sh"

ACTION=="remove", SUBSYSTEM=="usb",  ATTRS{idVendor}=="18a5", ATTRS{idProduct}=="0302", RUN+="/etc/demo/remove.sh"
I have restarted to udev rules with

Code:
sudo udevadm control --reload-rules
and don't get any error messages, I have tried inserting a usb stick with the following parameters

Code:
Bus 001 Device 008: ID 18a5:0302 Verbatim, Ltd 32GB Flash Drive
Which I believe should fire the script off when the usb drive is plugged in, I'm pretty sure I had this going once but now it does nothing, what am I doing wrong?

I've scoured the net but cant find anything anywhere, any thoughts/suggestions?

Thanks

Mike
 
Old 02-11-2016, 02:37 PM   #2
malekmustaq
Senior Member
 
Registered: Dec 2008
Location: root
Distribution: Slackware & BSD
Posts: 1,617

Rep: Reputation: 442Reputation: 442Reputation: 442Reputation: 442Reputation: 442
Check your log if the two events happened at the instant.
Or maybe your system have had no time enough to comple insert.sh before remove.sh takes over.
Try: comment the remove.sh line, reload udev, insert, and check by fdisk -l see if the drive is honored. If it is there then you are doing well.

Don't forget to
Quote:
sudo chmod +x /etc/demo/insert.sh
sudo chmod +x /etc/demo/remove.sh
Hope that helps. Good luck.

m.m.
 
Old 02-11-2016, 02:59 PM   #3
Mikeoxlarge
LQ Newbie
 
Registered: Feb 2016
Posts: 4

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by malekmustaq View Post
Check your log if the two events happened at the instant.
Or maybe your system have had no time enough to comple insert.sh before remove.sh takes over.
Try: comment the remove.sh line, reload udev, insert, and check by fdisk -l see if the drive is honored. If it is there then you are doing well.

Don't forget to


Hope that helps. Good luck.

m.m.
I've divided the udev rules in to two now as I had a suspicion that the fact there were two in the same rule may have been causing an issue, and yes I had forgotten to make the script executable lol I just facepalmed so hard I now have a sore nose

Soooo current status is the insert detection is working....just need to sort the removal one now


Cheers for your help


Mike
 
Old 02-11-2016, 04:31 PM   #4
Mikeoxlarge
LQ Newbie
 
Registered: Feb 2016
Posts: 4

Original Poster
Rep: Reputation: Disabled
Soooo we have progress....kind of, I have a script that I have now set to +x and it will run manually and do everything I want it to do when I fire the script from a command line however when I add it to the udev rules it doesnt seem to do anything at all now (I did get it to create a folder) what would cause it to be able to run fine from a command line but not from the udev rule?.

cheers

Mike
 
Old 02-12-2016, 10:52 AM   #5
malekmustaq
Senior Member
 
Registered: Dec 2008
Location: root
Distribution: Slackware & BSD
Posts: 1,617

Rep: Reputation: 442Reputation: 442Reputation: 442Reputation: 442Reputation: 442
Try check your dev rules.
Attributes?
Events?

Congratulation.
 
Old 02-12-2016, 11:04 AM   #6
Mikeoxlarge
LQ Newbie
 
Registered: Feb 2016
Posts: 4

Original Poster
Rep: Reputation: Disabled
Question getting closer

I have got this working on the box in question and have tried adding my scripts to this rule, on it's own it works perfectly and mounts the USB stick in the media folder in a folder it creates with the same name as the usb stick label, yet when I add my scripts to this they still dont "fire"


Code:
KERNEL!="sd[a-z][0-9]", GOTO="media_by_label_auto_mount_end"
# Import FS infos
IMPORT{program}="/sbin/blkid -o udev -p %N"
# Get a label if present, otherwise specify one
ENV{ID_FS_LABEL}!="", ENV{dir_name}="%E{ID_FS_LABEL}"
ENV{ID_FS_LABEL}=="", ENV{dir_name}="usbhd-%k"
# Global mount options
ACTION=="add", ENV{mount_options}="relatime"
# Filesystem-specific mount options
ACTION=="add", ENV{ID_FS_TYPE}=="vfat|ntfs", ENV{mount_options}="$env{mount_options},utf8,gid=100,umask=002"
# Mount the device
ACTION=="add", RUN+="/bin/mkdir -p /media/%E{dir_name}", RUN+="/bin/mount -o $env{mount_options} /dev/%k /media/%E{dir_name}"
# Clean up after removal
ACTION=="remove", ENV{dir_name}!="", RUN+="/bin/umount -l /media/%E{dir_name}", RUN+="/bin/rmdir /media/%E{dir_name}"
# Exit
LABEL="media_by_label_auto_mount_end"
I assumed it would be a simple matter of adding my scripts to the end of the "mount the device" line and the end of the "clean up after removal" line but nooooooo it's not that simple, so I have a script /etc/blah/blah.sh that I would like to run when the drive has mounted, where would I add it in here and what permissions would it need (it already has +x)

Cheers

Mike
 
  


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



Similar Threads
Thread Thread Starter Forum Replies Last Post
udev not working grouser Linux - Software 1 05-01-2013 02:14 PM
[SOLVED] udev and kernel 3.6.7 not working? dimm0k Slackware 10 11-25-2012 08:30 PM
Udev is not working fine. kshitij_dixit Linux - Newbie 0 01-15-2009 10:41 AM
slackware-current, udev 0.96, and custom udev rules not working rignes Slackware 6 08-10-2006 04:43 AM
Udev rules working but... cferron Linux - Hardware 5 03-24-2006 03:46 AM


All times are GMT -5. The time now is 01:16 PM.

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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration