Automount script barfs

The place to post if you need help or advice

Moderators: ChrisThornett, LXF moderators

Postby Arthur_Dent » Fri Apr 25, 2014 7:51 pm

Well I'm making some (limited) progress. Looking at udevadm info
produces lots of output. Focusing on the section below (I believe you cannot mix attributes from different sections?) I have tried to narrow the udev rule.

Using the rule:
Code: Select all
ACTION=="add", SUBSYSTEM=="usb", ATTRS{idVendor}=="8564", ATTRS{serial}=="71519F31", RUN:="/root/scripts/mount_USBStick1.sh &"
Now produces only two runs of the script!

What can I do to get it down to just one?

Code: Select all
# udevadm info --attribute-walk --name /dev/sdc1 | less
...
  looking at parent device '/devices/pci0000:00/0000:00:1d.7/usb2/2-6':
    KERNELS=="2-6"
    SUBSYSTEMS=="usb"
    DRIVERS=="usb"
    ATTRS{bDeviceSubClass}=="00"
    ATTRS{bDeviceProtocol}=="00"
    ATTRS{devpath}=="6"
    ATTRS{idVendor}=="8564"
    ATTRS{speed}=="480"
    ATTRS{bNumInterfaces}==" 1"
    ATTRS{bConfigurationValue}=="1"
    ATTRS{bMaxPacketSize0}=="64"
    ATTRS{busnum}=="2"
    ATTRS{devnum}=="34"
    ATTRS{configuration}==""
    ATTRS{bMaxPower}=="200mA"
    ATTRS{authorized}=="1"
    ATTRS{bmAttributes}=="80"
    ATTRS{bNumConfigurations}=="1"
    ATTRS{maxchild}=="0"
    ATTRS{bcdDevice}=="0112"
    ATTRS{avoid_reset_quirk}=="0"
    ATTRS{quirks}=="0x0"
    ATTRS{serial}=="71519F31"
    ATTRS{version}==" 2.00"
    ATTRS{urbnum}=="814"
    ATTRS{ltm_capable}=="no"
    ATTRS{manufacturer}=="JetFlash"
    ATTRS{removable}=="unknown"
    ATTRS{idProduct}=="1000"
    ATTRS{bDeviceClass}=="00"
    ATTRS{product}=="Mass Storage Device"


Here is the output of udevadm monitor --subsystem-match="usb":
Code: Select all
# udevadm monitor --subsystem-match="usb"
monitor will print the received events for:
UDEV - the event which udev sends out after rule processing
KERNEL - the kernel uevent

KERNEL[386993.075219] remove   /devices/pci0000:00/0000:00:1d.7/usb2/2-6/2-6:1.0 (usb)
KERNEL[386993.075357] remove   /devices/pci0000:00/0000:00:1d.7/usb2/2-6 (usb)
UDEV  [386993.108098] remove   /devices/pci0000:00/0000:00:1d.7/usb2/2-6/2-6:1.0 (usb)
UDEV  [386993.110601] remove   /devices/pci0000:00/0000:00:1d.7/usb2/2-6 (usb)
KERNEL[386996.678941] add      /devices/pci0000:00/0000:00:1d.7/usb2/2-5 (usb)
KERNEL[386996.679545] add      /devices/pci0000:00/0000:00:1d.7/usb2/2-5/2-5:1.0 (usb)
UDEV  [386998.854067] add      /devices/pci0000:00/0000:00:1d.7/usb2/2-5 (usb)
UDEV  [387001.218881] add      /devices/pci0000:00/0000:00:1d.7/usb2/2-5/2-5:1.0 (usb)
Arthur_Dent
LXF regular
 
Posts: 219
Joined: Mon Jan 02, 2006 11:05 am
Location: London

Postby Arthur_Dent » Fri Apr 25, 2014 8:42 pm

Update:

I think I may have got it!

I just spotted a typo in my udev rule. It should have been
Code: Select all
SUBSYSTEMS=="usb"
(note it is SUBSYSTEMS - not SUBSYSTEM as I had previously).

I haven't tested fully yet, but that seemed (on the first and only - so far - attempt) to produce only one (!) run of the script!

If anyone can spot anything else I've got wrong please do let me know. I will try to test this more tomorrow.

Thanks!
Arthur_Dent
LXF regular
 
Posts: 219
Joined: Mon Jan 02, 2006 11:05 am
Location: London

Postby nelz » Fri Apr 25, 2014 8:57 pm

Yes, it's SUBSYSTEMS for usb and SUBSYSTEM for scsi - logical, eh?

You can't mix attributes from section but you can mix some variables. The easiest way to know for sure what works and what does't is to try it. It's hard to do any damage with a udev rule, unless it includes something like RUN="rm -fr /*" :shock:
"Insanity: doing the same thing over and over again and expecting different results." (Albert Einstein)
User avatar
nelz
Site admin
 
Posts: 8504
Joined: Mon Apr 04, 2005 11:52 am
Location: Warrington, UK

Postby Arthur_Dent » Sat Apr 26, 2014 11:00 am

Well, with enormous thanks to Nelz, the problem I came here to solve appears to be fixed. UDEV, on insertion of the USB stick, calls the script which performs its functions only once.

However, the idea behind it has failed. During my testing, for the purposes of expediency, I have been using a relatively small text file for the copying part of the script.

The actual tar.gz file to be copied is about 4.3gb.

On running the script with the actual file, sadly the transfer seems to get to about 500mb and then stops.

I was aware (and Nelz reminded me) that udev is designed only for short foreground tasks. I thought however that handing-off to a detached script would get over this problem. On re-reading man udev however I noticed this:
Code: Select all
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.
Have I fallen foul of this? Is there any way around it?

Nelz, both you (in your LXF article) and Daniel Drake (in the link you pointed me to) suggest using a udev rule to mount and automatically download photos from a camera as an example of how a udev rule might be used. Would this not also fall foul of this problem?

Is there any alternative?

Thanks again for all the help so far...

Mark
Arthur_Dent
LXF regular
 
Posts: 219
Joined: Mon Jan 02, 2006 11:05 am
Location: London

Postby nelz » Sat Apr 26, 2014 9:52 pm

Possibly, depending on the timeout, but reading from flash frive is generally faster than writing.

However, I've thought of another way of doing this, by using icrond to watch for the creation of the stick's mount point - letting your desktop's automounter take care of mounting the stick. Put something like this in your incrontab

Code: Select all
/media IN_CREATE /your/script $#


This runs your script, passing it the name of the created directory. Your script can then check if this is the backup device before proceeding.
"Insanity: doing the same thing over and over again and expecting different results." (Albert Einstein)
User avatar
nelz
Site admin
 
Posts: 8504
Joined: Mon Apr 04, 2005 11:52 am
Location: Warrington, UK

Postby Arthur_Dent » Mon Apr 28, 2014 9:40 am

Hi Nelz,

That looks like a brilliant idea. I have never heard of IN_CREATE before.

Unfortunatley I am away from my computer for a couple of days, but I will try it as soon as I can.

Just one question if I may:

Given that this method is using the desktop automounter, do you have to be logged in for this to work?

The machine in question is a server which runs headless and I do not (normally) log in to it. Any maintenence I do using ssh...

Thanks again for all your help. Much appreciated...
Arthur_Dent
LXF regular
 
Posts: 219
Joined: Mon Jan 02, 2006 11:05 am
Location: London

Postby nelz » Mon Apr 28, 2014 10:45 am

In that case, have udev mount the device and let incrond do the rest.
"Insanity: doing the same thing over and over again and expecting different results." (Albert Einstein)
User avatar
nelz
Site admin
 
Posts: 8504
Joined: Mon Apr 04, 2005 11:52 am
Location: Warrington, UK

Previous

Return to Help!

Who is online

Users browsing this forum: No registered users and 1 guest