0

Say I have a script script.sh. How can I make it execute whenever a bootable medium is inserted? So lets say I stick a bootable cd into my PC, I want script.sh to run on insertion without rebooting my machine. Similar to:

How to run custom scripts upon USB device plug-in?

but I don't want to distinguish between IDs and I want it to affect more than USBs... CDs and Harddrives as well.

Also,if possible, I would really like to pass information about the drive/cd to the script when it is inserted... My script is supposed to create a efi boot entry based on this inserted device, so I need to pass the devices information (port location, label, etc.) to script.sh.

Thanks,

1

The answer is the same as in How to run custom scripts upon USB device plug-in?. You simply don't specify what you don't need to:

Original:

KERNEL=="sd*", ATTRS{vendor}=="Yoyodyne", ATTRS{model}=="XYZ42", ATTRS{serial}=="123465789", RUN+="/pathto/script"

Without caring about the vendor, model, serial:

KERNEL=="sd*", RUN+="/pathto/script"

You can pass parameters to the script, %k for example is substituted by the device name.

Check the man page for the full list and more information.

And I suggest using:

$ udevadm monitor

To debug the rules.

1
  • I didnt think it would be that easy! Thanks! – ragnvaldr.js Apr 19 '20 at 17:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.