Linux Format forums Forum Index Linux Format forums
Help, discussion, magazine feedback and more
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Automount script barfs
Goto page Previous  1, 2
 
Post new topic   Reply to topic    Linux Format forums Forum Index -> Help!
View previous topic :: View next topic  
Author Message
Arthur_Dent
LXF regular


Joined: Mon Jan 02, 2006 11:05 am
Posts: 219
Location: London

PostPosted: Fri Apr 25, 2014 8:51 pm    Post subject: Reply with quote

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:
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:
# 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:
# 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)
Back to top
View user's profile Send private message
Arthur_Dent
LXF regular


Joined: Mon Jan 02, 2006 11:05 am
Posts: 219
Location: London

PostPosted: Fri Apr 25, 2014 9:42 pm    Post subject: Reply with quote

Update:

I think I may have got it!

I just spotted a typo in my udev rule. It should have been
Code:
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!
Back to top
View user's profile Send private message
nelz
Site admin


Joined: Mon Apr 04, 2005 12:52 pm
Posts: 8450
Location: Warrington, UK

PostPosted: Fri Apr 25, 2014 9:57 pm    Post subject: Reply with quote

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 /*" Shocked
_________________
"Insanity: doing the same thing over and over again and expecting different results." (Albert Einstein)
Back to top
View user's profile Send private message
Arthur_Dent
LXF regular


Joined: Mon Jan 02, 2006 11:05 am
Posts: 219
Location: London

PostPosted: Sat Apr 26, 2014 12:00 pm    Post subject: Reply with quote

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:
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
Back to top
View user's profile Send private message
nelz
Site admin


Joined: Mon Apr 04, 2005 12:52 pm
Posts: 8450
Location: Warrington, UK

PostPosted: Sat Apr 26, 2014 10:52 pm    Post subject: Reply with quote

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:
/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)
Back to top
View user's profile Send private message
Arthur_Dent
LXF regular


Joined: Mon Jan 02, 2006 11:05 am
Posts: 219
Location: London

PostPosted: Mon Apr 28, 2014 10:40 am    Post subject: Reply with quote

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...
Back to top
View user's profile Send private message
nelz
Site admin


Joined: Mon Apr 04, 2005 12:52 pm
Posts: 8450
Location: Warrington, UK

PostPosted: Mon Apr 28, 2014 11:45 am    Post subject: Reply with quote

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)
Back to top
View user's profile Send private message
View previous topic :: View next topic  
Display posts from previous:   
Post new topic   Reply to topic    Linux Format forums Forum Index -> Help! All times are GMT
Goto page Previous  1, 2
Page 2 of 2

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
Linux Format forums topic RSS feed 


Powered by phpBB © 2001, 2005 phpBB Group


Copyright 2011 Future Publishing, all rights reserved.


Web hosting by UKFast