Results 1 to 8 of 8

Thread: start-up script to detect when external media is plugged in

  1. #1
    Join Date
    Aug 2012
    Beans
    623

    start-up script to detect when external media is plugged in

    Hello,
    Is there a start-up script or something which I can edit, so that it detects when my pendrive is plugged in.

    Basically, when I plug-in my pendrive, I want the system to detect that and then call another program which I have written, instead of me manually running the program from the terminal after the pendrive is plugged-in.

    Thanks.

  2. #2
    Join Date
    Aug 2006
    Beans
    13,354
    Distro
    Ubuntu Mate 20.04 Focal Fossa

    Re: start-up script to detect when external media is plugged in


  3. #3
    Join Date
    Aug 2012
    Beans
    623

    Re: start-up script to detect when external media is plugged in

    Quote Originally Posted by mikewhatever View Post
    Thanks mike for the reply. But I still have some trouble getting it to work.

    I checked the output of the lsusb -v command, and it's as follows
    Code:
    Bus 002 Device 007: ID 8564:1000
    Device Descriptor:
      bLength                18
      ..
      ..
      idVendor           0x8564
      idProduct          0x1000
    So I created a new file as follows
    Code:
    IAMTubby@IAMTubby-Inspiron-1545:/etc/udev/rules.d$ ls
    100-persistent-transcend.rules  70-persistent-cd.rules  70-persistent-net.rules  README
    IAMTubby@IAMTubby-Inspiron-1545:/etc/udev/rules.d$ cat 100-persistent-transcend.rules 
    ACTION=="add", ATTRS{idVendor}=="0x8564", ATTRS{idProduct}=="0x1000", RUN+="/home/IAMTubby/Desktop/run.sh"
    My script is as follows
    Code:
    IAMTubby@IAMTubby-Inspiron-1545:~/Desktop$ cat run.sh 
    sleep 10
    touch transcendfile.txt
    I tried removing and inserting the pendrive few times, but the script doesn't seem to run as suggested by the ps output.

    Please advise.
    Thanks.

    PS : Please find attached the output of my lsusb -v command. Have highlighted the details for my pendrive in blue which is 8564:1000
    Attached Files Attached Files
    Last edited by IAMTubby; April 17th, 2014 at 12:32 PM.

  4. #4
    Join Date
    Apr 2012
    Beans
    7,256

    Re: start-up script to detect when external media is plugged in

    Double check the IdVendor and IdProduct fields using the udevadm attribute walk instead of lsusb - it may be subtly different (e.g. minus the 0x prefix)

    Code:
    udevadm info -a -p  $(udevadm info -q path -n /dev/sde) | less
    where you have replaced /dev/sde with the block device file of your device

  5. #5
    Join Date
    Aug 2006
    Beans
    13,354
    Distro
    Ubuntu Mate 20.04 Focal Fossa

    Re: start-up script to detect when external media is plugged in

    How about ATTRS{idVendor}=="8564", ATTRS{idProduct}=="1000" instead of ATTRS{idVendor}=="0x8564", ATTRS{idProduct}=="0x1000"?

  6. #6
    Join Date
    Apr 2012
    Beans
    7,256

    Re: start-up script to detect when external media is plugged in

    ^^^ that's exactly what I'm hinting at (but verifying with udevadm would be a good step imho)

  7. #7
    Join Date
    Aug 2012
    Beans
    623

    Re: start-up script to detect when external media is plugged in

    Quote Originally Posted by steeldriver View Post
    Double check the IdVendor and IdProduct fields using the udevadm attribute walk instead of lsusb - it may be subtly different
    steeldriver, thanks for the reply. But I'm still not able to get it

    udevadm info -a -p $(udevadm info -q path -n /dev/sde) | less where you have replaced /dev/sde with the block device file of your device
    To find the block device file, I did a mount and got the output as /dev/sdb1 on /media/Transcend type vfat (rw,nosuid,nodev,uid=1000,gid=1000,shortname=mixed ,dmask=0077,utf8=1,showexec,flush,uhelper=udisks)

    I then ran the command udevadm info -a -p $(udevadm info -q path -n /dev/sdb1) | less

    However, the output I get is same as before. Please find the required part of the output below
    ATTRS{idVendor}=="8564"
    ATTRS{idProduct}=="1000"


    Please find attached the entire output.
    Attached Files Attached Files

  8. #8
    Join Date
    Aug 2012
    Beans
    623

    Re: start-up script to detect when external media is plugged in

    Quote Originally Posted by mikewhatever View Post
    How about ATTRS{idVendor}=="8564", ATTRS{idProduct}=="1000" instead of ATTRS{idVendor}=="0x8564", ATTRS{idProduct}=="0x1000"?
    mike, just tried that, but doesn't seem to work.

Bookmarks

Posting Permissions

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