LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 02-07-2014, 12:03 PM   #1
shams
Member
 
Registered: Jan 2004
Posts: 537

Rep: Reputation: 30
Question udev rules not working?


I want to run a script when usb flash device is connected in ubuntu 13.10, this is the /etc/udev/rules.d/91.test.rule:

Quote:
KERNEL=="sdc", ACTION=="add", SUBSYSTEMS=="usb", ATTRS{idVendor}=="0951", ATTRS{idProduct}=="1607", RUN+="/home/user/tmp/test.sh"
this is the test.sh:

Quote:
#! /bin/sh

if [ "${ACTION}" = "add" ] && [ -f "${DEVICE}" ]
then
echo ${DEVICE} >> /var/log/backuptousbdrive.log
fi
But this is not working?
 
Old 02-08-2014, 05:42 AM   #2
Shadow_7
Senior Member
 
Registered: Feb 2003
Distribution: debian
Posts: 4,137
Blog Entries: 1

Rep: Reputation: 874Reputation: 874Reputation: 874Reputation: 874Reputation: 874Reputation: 874Reputation: 874
What user would that launched process run as? nobody? And does it have write permissions to /var/log/? Perhaps another method of verifying if it works or not.
 
Old 02-08-2014, 10:51 AM   #3
shams
Member
 
Registered: Jan 2004
Posts: 537

Original Poster
Rep: Reputation: 30
Thanks for reply, the problem is not with the permission but the with the rule itself, i tested with other programs like this one:

Quote:
KERNEL=="sdc", ACTION=="add", SUBSYSTEMS=="usb", ATTRS{idVendor}=="0951", ATTRS{idProduct}=="1607", RUN+="/usr/bin/bluefish"
The rule should launch the bluefish that can be as user or root no problem but not working.
 
Old 02-09-2014, 08:59 AM   #4
Shadow_7
Senior Member
 
Registered: Feb 2003
Distribution: debian
Posts: 4,137
Blog Entries: 1

Rep: Reputation: 874Reputation: 874Reputation: 874Reputation: 874Reputation: 874Reputation: 874Reputation: 874
According to the manpage.

--- Starting daemons and other long running processes is not appropriate for udev; the forked processes, detached or not, will be unconditionally killed after the event handling has finished. ---

So whatever it does will likely persist for as long as it takes to create the /dev/ names for the device. Or I could be wrong. You'll likely need to setup a daemon to lauch whatever application and the RUN would pass some form of communication to that daemon to do something (like create a file and if a file exists the daemon launches an application and removes the file to avoid duplication of efforts).

In the case of a GUI application you'll need the magic cookie and DISPLAY and XAUTHORITY vars set for the user who launches that application. AKA the .Xauthority file depending on distro and configuration. The user who launches X has those configured already because it launched X. Any other user wanting to share the X session has to do that manually, unless the display manager handles that process.
 
  


Reply



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
custom udev rules not working amboxer21 Programming 1 12-28-2013 06:10 PM
[SOLVED] udev rules not working properly jyotir.roy Linux - Newbie 1 11-05-2012 09:04 PM
[SOLVED] udev rules suddenly stopped working in 9.10 ibwood Ubuntu 1 08-11-2010 10:31 AM
slackware-current, udev 0.96, and custom udev rules not working rignes Slackware 6 08-10-2006 03:43 AM
Udev rules working but... cferron Linux - Hardware 5 03-24-2006 02:46 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 12: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