Page 1 of 2 12 LastLast
Results 1 to 10 of 15

Thread: mktemp - duplicate files/dirs ...

  1. #1

    Default mktemp - duplicate files/dirs ...

    Under Leap 15, this simple assignment:

    MOUNT_POINT=$(mktemp -d "/tmp/butmp.XXXX")

    gives me ONE directory entry.


    But when executed as an action (script) from a udev rule (RUN+=...)
    I consistently get TWO directory entries (with a different extension) ??

    (same with file instead of directory)

    What did I get wrong ?

  2. #2
    Join Date
    Jun 2008
    Location
    Netherlands
    Posts
    23,786

    Default Re: mktemp - duplicate files/dirs ...

    Sorry, but I doubt people can do much which what you tell. Please be more explicit. Which names do you get., etc. Keeping all details a secret will not help anybody to get an Eureka moment.
    Henk van Velden

  3. #3

    Default Re: mktemp - duplicate files/dirs ...

    I'll try be more explicit... ;-)

    The simple script (saved as "abu.sh") assigns a name to the variable MOUNT_POINT, and in the meantime creates a temporary directory with that same name (as per "man mktemp").
    So i do get a name for MOUNT_POINT (e.g. "/tmp/butmp.eIXz") and at the same time a directory is indeed created with that name ("/tmp/butmp.eIXz") - when run from the console...

    But the purpose is to have this script executed as an action to a udev-rule (in my case: /etc/udev/rules.d):

    SUBSYSTEM=="block", ACTION=="add", ATTRS{idVendor}=="174c", SYMLINK+="abul%n", RUN+="abu.sh"

    But when i do plug-in that block device, I do get a name assigned to "MOUNT_POINT", but TWO directories are created under /tmp/ (conform the same template).

    So the variable MOUNT_POINT is assigned a name (e.g. "/tmp/butmp.om3T"), while two directories are created (e.g. "/tmp/butmp.om3T" AND "/tmp/butmp.rbyr")...

    I think there must a some problem here ?

  4. #4
    Join Date
    Jun 2008
    Location
    Netherlands
    Posts
    23,786

    Default Re: mktemp - duplicate files/dirs ...

    I will also try to be more specific.

    There is an important, but not easy to find feature on the forums.

    Please in the future use CODE tags around copied/pasted computer text in a post. It is the # button in the tool bar of the post editor. When applicable copy/paste complete, that is including the prompt, the command, the output and the next prompt.

    Then, why do you not post that script? There could be an error/misunderstanding there and how are we assumed to check that? At least it would provide us with the exect call of mktemp and not your vague: as per "man mktemp"

    Then do such a call and show us what is created: the script execution command, it's output and the ls -ls -l of what is created. Then we can see date/time/ownership ........

    Then show us the complete udev rule:
    Code:
    cat /etc/udev/rules.d/whatever-the-name-is
    Etc.
    ===========
    This is very general for problem posting/asking for help:

    Remind that we can not look over your shoulder and that we rely completely on your information. Also, you are now realy in touch with your problem, we aren't,. So, do not assume that we have an intimate insight in your problem. Also do not assume people do what you try to do all the time and thus it is only a case of half explanation and then others say: of course he means .......

    Sometine in the past another member here said: we do not trust you, we only trust computer output. That is a bit harsh, but human people are notorious for skipping information, jumping to conclusions, etc. The best is to offer the real output because others may see what you didn't.
    Last edited by hcvv; 06-Dec-2018 at 11:22.
    Henk van Velden

  5. #5

    Default Re: mktemp - duplicate files/dirs ...

    ...we do not trust you, we only trust computer output...
    I'll remember this as a real good (and just) quote!

    But back to business, here you have the rule, the script and the ouput (working as root on console)

    Code:
    hanoi:~ # cat /etc/udev/rules.d/10-abu.rules 
    SUBSYSTEM=="block", ACTION=="add", ATTRS{idVendor}=="174c", SYMLINK+="abul%n", RUN+="/bin/abu.sh"
    
    hanoi:~ # cat /bin/abu.sh 
    #!/bin/bash
    MOUNT_POINT=$(mktemp -d "/tmp/butmp.XXXX")
    echo "$MOUNT_POINT" |  xxd > /tmp/buNAME.TXT
    exit
    
    hanoi:~ # /bin/abu.sh
    
    hanoi:~ # ll /tmp/bu*
    -rw-r--r-- 1 root root 68 Dec  7 10:29 /tmp/buNAME.TXT
    
    /tmp/butmp.mOag:
    total 0
    drwx------  2 root root  40 Dec  7 10:29 ./
    drwxrwxrwt 17 root root 380 Dec  7 10:29 ../
    
    hanoi:~ #
    This is as it should be: one temporary directory has been created in /tmp

    But when i do insert the usb-block device (referenced as ATTRS{idVendor}=="174c" in the udev-rule) in the usb-port I get two directory entries, like this:

    Code:
    hanoi:~ # ll /tmp/bu*
    -rw-r--r-- 1 root root 68 Dec  7 10:35 /tmp/buNAME.TXT
    
    /tmp/butmp.7BOE:
    total 0
    drwx------  2 root root  40 Dec  7 10:35 ./
    drwxrwxrwt 18 root root 400 Dec  7 10:35 ../
    
    /tmp/butmp.Zg7W:
    total 0
    drwx------  2 root root  40 Dec  7 10:35 ./
    drwxrwxrwt 18 root root 400 Dec  7 10:35 ../
    
    hanoi:~ # cat /tmp/buNAME.TXT 
    00000000: 2f74 6d70 2f62 7574 6d70 2e5a 6737 570a  /tmp/butmp.Zg7W.
    My question is really that simple: what do I do wrong ?

  6. #6
    Join Date
    Jun 2008
    Location
    Netherlands
    Posts
    23,786

    Default Re: mktemp - duplicate files/dirs ...

    That is much better! Now I see that your script is in fact at /bin/abu.sh and not at abu.sh as you posted earlier and of which I had my doubts.

    What I can imagine here is that on connecting the device the hardware sees two connections short after each other (trembling fingers, or bad contact, or .....). Could you check with e.g. dmesg what is happening at connection?

    Just a thought.
    Henk van Velden

  7. #7

    Default Re: mktemp - duplicate files/dirs ...

    Quote Originally Posted by hcvv View Post
    That is much better!
    You see that I can if I want to ;-)

    ... the hardware sees two connections short after each other (trembling fingers...
    Heaven forbid - i don't drink that much ! (although i'm 68).

    dmesg tells me (yes - i was absent between 7996 and 8232 ...):

    Code:
    [ 7996.867819] [drm] Reducing the compressed framebuffer size. This may lead to less power savings than a non-reduced-size. Try to increase stolen memory size if available in BIOS.
    [ 8232.670755] usb 2-2.1: new SuperSpeed USB device number 9 using xhci_hcd
    [ 8232.691871] usb 2-2.1: New USB device found, idVendor=174c, idProduct=1153
    [ 8232.691881] usb 2-2.1: New USB device strings: Mfr=2, Product=3, SerialNumber=1
    [ 8232.691888] usb 2-2.1: Product: AS2115
    [ 8232.691894] usb 2-2.1: Manufacturer: ASMedia
    [ 8232.691900] usb 2-2.1: SerialNumber: 00000000000000000000
    [ 8232.693391] usb-storage 2-2.1:1.0: USB Mass Storage device detected
    [ 8232.694828] scsi host4: usb-storage 2-2.1:1.0
    [ 8233.728041] scsi 4:0:0:0: Direct-Access     ASMT     2115             0    PQ: 0 ANSI: 6
    [ 8233.728890] sd 4:0:0:0: Attached scsi generic sg2 type 0
    [ 8233.736389] sd 4:0:0:0: [sdc] 468862128 512-byte logical blocks: (240 GB/224 GiB)
    [ 8233.736708] sd 4:0:0:0: [sdc] Write Protect is off
    [ 8233.736717] sd 4:0:0:0: [sdc] Mode Sense: 43 00 00 00
    [ 8233.736997] sd 4:0:0:0: [sdc] Write cache: enabled, read cache: enabled, doesn't support DPO or FUA
    [ 8233.743052]  sdc: sdc1
    [ 8233.747543] sd 4:0:0:0: [sdc] Attached SCSI disk
    But I do think you have a point: there must be something that 'sees' two connections.

    Could it be the 'automatic notification' is the cause (remember: I'm working on Suse - Leap 15 and when I insert the block device I get a message form the device notifier presenting me the possibility to mount - which i cancel of course)? But then, I don't know how to disable this notification...

  8. #8
    Join Date
    Jun 2008
    Location
    Netherlands
    Posts
    23,786

    Default Re: mktemp - duplicate files/dirs ...

    Quote Originally Posted by baudrez View Post
    Heaven forbid - i don't drink that much ! (although i'm 68).
    Well, I found out that at 73 I realy drink less and less (but no decrease on non-alcoholic).
    Quote Originally Posted by baudrez View Post
    dmesg tells me (yes - i was absent between 7996 and 8232 ...):

    Could it be the 'automatic notification' is the cause (remember: I'm working on Suse - Leap 15 and when I insert the block device I get a message form the device notifier presenting me the possibility to mount - which i cancel of course)? But then, I don't know how to disable this notification...
    That notification is from the desktop, but it is of course triggered by udev and udisk. But, that mechanism will mount it for you (when you answer the notification or try to use it otherwise) on a place in /run/media/<user-name>/<some fs-identification> (or similar, the /run/media/ part is something that differs now and then).

    That does not explain the two directories you get IMHO.

    I know of only one way to suppress the desktop doing this. That is by having the device in /etc/fstab. The device identification must then of course be something that can be coupled to the device, lke a LABEL or an UUID.

    BTW, I think you can get some confirmation of a double action by not overwriting
    Code:
    > /tmp/buNAME.TXT
    but by adding
    Code:
    >> /tmp/buNAME.TXT
    You will then have a history of the number of calls of the script.
    Henk van Velden

  9. #9

    Default Re: mktemp - duplicate files/dirs ...

    Quote Originally Posted by hcvv View Post
    BTW, I think you can get some confirmation of a double action by not overwriting ...
    Been there - done that, and yes:
    Code:
    hanoi:/tmp # cat buNAME.TXT 
    00000000: 2f74 6d70 2f62 7574 6d70 2e54 634d 300a  /tmp/butmp.TcM0.
    00000000: 2f74 6d70 2f62 7574 6d70 2e33 4534 550a  /tmp/butmp.3E4U.

  10. #10
    Join Date
    Jun 2008
    Location
    Netherlands
    Posts
    23,786

    Default Re: mktemp - duplicate files/dirs ...

    My conclusion, it is not mktemp that acts double, but your script is called twice.

    Any chance you have your udev rule a second time somewhere?
    Again, just guessing and offering starting points for thought.
    Henk van Velden

Page 1 of 2 12 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •