nebulloyd
Posts: 19
Joined: Thu Nov 10, 2016 5:39 pm

How to create new file in udev

Sun Nov 13, 2016 5:21 pm

Simple question here from someone that has never used udev. How can I create a new file for a new udev rule and rsync? No explanation is too simple! I've tried combinations of cat, > and touch. no luck with anything I can dream up. Please help or I may melt.
RPi 3B
Macbook Pro 2011

User avatar
DougieLawson
Posts: 39121
Joined: Sun Jun 16, 2013 11:19 pm
Location: A small cave in deepest darkest Basingstoke, UK
Contact: Website Twitter

Re: How to create new file in udev

Sun Nov 13, 2016 5:40 pm

/etc/udev/rules.d/71-usb-stick

Code: Select all

KERNEL=="sd*", SUBSYSTEMS=="scsi", DRIVERS=="sd", SYMLINK+="stick",  RUN+="/usr/local/bin/stick_drive $kernel'"
SUBSYSTEMS=="usb", ATTRS{removable}=="removable", RUN+="/usr/local/bin/flash_drive $kernel'"
Your biggest problem will be that what ever program you start from a RUN+= clause only gets about ten seconds before udev kills it. So you need to make it trigger some other process within a long running daemon.
udev man page wrote: This can only be used for very short-running foreground tasks.
Running an event process for a long period of time may block all
further events for this or a dependent device.

Starting daemons or 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.
Note: Any requirement to use a crystal ball or mind reading will result in me ignoring your question.

Criticising any questions is banned on this forum.

Any DMs sent on Twitter will be answered next month.
All non-medical doctors are on my foes list.

nebulloyd
Posts: 19
Joined: Thu Nov 10, 2016 5:39 pm

Re: How to create new file in udev

Sun Nov 13, 2016 6:55 pm

Thank you very much for you response, but I still don't understand how the file is made to which I could paste that code. I am really asking for a key by key explanation I guess. I just tried using that file path but I get the same error as always...(see below)

Code: Select all

pi@raspberrypi:~ $ /etc/udev/rules.d/71-garmingps
bash: /etc/udev/rules.d/71-garmingps: No such file or directory
pi@raspberrypi:~ $ /etc/udev/rules.d/71-garmingps.rules
bash: /etc/udev/rules.d/71-garmingps.rules: No such file or directory
pi@raspberrypi:~ $ 
it is for this device

Code: Select all

Bus 001 Device 004: ID 091e:2459 Garmin International GPSmap 62/78 series
any suggestions?
RPi 3B
Macbook Pro 2011

nebulloyd
Posts: 19
Joined: Thu Nov 10, 2016 5:39 pm

Re: How to create new file in udev

Sun Nov 13, 2016 7:12 pm

ok so I created a file using the following command

Code: Select all

sudo nano /etc/udev/rules.d/71-garmingps.rules
will there be any issue down the line with this??
RPi 3B
Macbook Pro 2011

User avatar
DougieLawson
Posts: 39121
Joined: Sun Jun 16, 2013 11:19 pm
Location: A small cave in deepest darkest Basingstoke, UK
Contact: Website Twitter

Re: How to create new file in udev

Sun Nov 13, 2016 7:31 pm

It depends what you do with the RUN+= clause. That's where your problems will appear. Those things get killed very quickly after the USB stick gets inserted.
Note: Any requirement to use a crystal ball or mind reading will result in me ignoring your question.

Criticising any questions is banned on this forum.

Any DMs sent on Twitter will be answered next month.
All non-medical doctors are on my foes list.

User avatar
karrika
Posts: 1124
Joined: Mon Oct 19, 2015 6:21 am
Location: Finland

Re: How to create new file in udev

Sun Nov 13, 2016 7:39 pm

DougieLawson wrote:It depends what you do with the RUN+= clause. That's where your problems will appear. Those things get killed very quickly after the USB stick gets inserted.
That is news for me. I am constantly doing 4 - 6 hour update runs without anyone trying to interrupt the action. Has it changed since Lucid?

This RUN+ has worked for me just fine (running time between 1 min 30 sec - 6 hours):

Code: Select all

ACTION=="add", \
 RUN+="/usr/local/bin/blink", \
 RUN+="/bin/mkdir -p /tmp/usb", \
 RUN+="/bin/chmod a+rwx /tmp/usb", \
 RUN+="/bin/mount -o $env{mount_options} /dev/%k /tmp/usb", \
 RUN+="/usr/local/bin/processusb" \
 RUN+="/usr/local/bin/light"

nebulloyd
Posts: 19
Joined: Thu Nov 10, 2016 5:39 pm

Re: How to create new file in udev

Sun Nov 13, 2016 7:52 pm

Ok this thread has become very similar to my other one. I think for the sake of everyone's sanity we should continue the conversation here: viewtopic.php?f=91&t=165326&p=1067335#p1067335
RPi 3B
Macbook Pro 2011

Return to “Beginners”