Welcome to the Linux Foundation Forum!

Can't get udev rule to work on Ubuntu or Fedora


I can't get my udev rule to fire when I plug in a usb stick.

I've tried many different rules, but the ones I've settled on here are in [6] in the screenshots.
Also I tried with my fedora install usb, an RTL-SDR thing, and a freshly formatted USB stick with one ext4 partition.

[1] - plugged in the usb stick and grep for SUBSYSTEM in udevadm info
[2] - plugged in the usb stick and grep for DEVTYPE in udevadm info
[3] - show the usbstick is there in lsblk
[4] - cat out the script I plan to attach to my rule with RUN+=
[5] - the script is in the right spot, /opt/script.sh. It's executable and owner/group is root
[6] - cat out the rules. There are 2 different ones I tried
[7] - run lsblk again. See the usb stick has been unplugged
[8] - reload rules with udevadm control --reload
[9] - show the usb stick has been reinserted.
[10] - the script didnt work! It was supposed to create a file in /tmp

back to poking around . . .

Any tips appreciated!

Comments

  • NEVERMIND I believe I was missing the shebang #!/bin/sh at the top of the script.

    Not sure if there is a limitation on which interpreters can be put there?

    Anyway, after playing more now it works and the main change seems to be having added the #!/bin/sh at the top of the script.

  • Hi @MelvynDrag ,

    Not sure if there is a limitation on which interpreters can be put there?

    What do you mean? I see it more as a feature, because you can choose what shell you can use, and so use it's own features.

    Regards,
    Luis.

  • Yea I agree its great

    I meant I was wondering if it's possible to use any scripting language, like can I put #!/usr/bin/python3 and make it a python script? Or is it limited to certain shells or something.

    It was I think a dumb question in the middle of the night. I dont think it's restricted to /bin/sh or /usr/bin/bash or anything.

    A dumb question

    Thanks to you and coop for being so active in the forum, it's super helpful

  • coop
    coop Posts: 915

    I don't believe there is much restriction on the interpreter. Try it :)

Categories

Upcoming Training