On Tue, 16 Nov 2021 08:11:07 -0500, The Natural Philosopher <t...@invalid.invalid> wrote:
>> inserts a usb flash drive into a usb port on
>> demand with no graphical UI at all running on this machine.
> Is dbus the best way to achieve that?
> ISTR there is another mechanism designed to be triggered on drive
> insertion/removal - udev?
It is udev, controlled by a rule. For example ...
$ cat /etc/udev/rules.d/00-myusb.rules
# udev rules file for my usb drive
ACTION!="add", GOTO="myusb_rules_end"
SUBSYSTEM!="block", GOTO="myusb_rules_end"
ATTR{partition}=="1", RUN+="/bin/logger -t myusb drive inserted %k"
LABEL="myusb_rules_end"
Just change it to run the desired script instead of logger.
Another example, if you have a specific script to run for a specific usb drive ...
$ cat /etc/udev/rules.d/00-myusb2.rules
# udev rules file for my usb drive
ACTION!="add", GOTO="myusb2_rules_end"
KERNEL=="sd?1", ATTRS{serial}=="070526931096D296" , ACTION=="add", RUN+="/bin/logger -t cryptdrive inserted %k"
LABEL="myusb2_rules_end"
Regards, Dave Hodgins