DBUS and classic mounts

3 views
Skip to first unread message

Henning Hucke

unread,
Nov 16, 2021, 7:37:45 AM11/16/21
to
Hi everybody,

I'm an admin for round about the last 25 years working with diverse
flavours of unixoid operating systems and especially with linux.

This means that I work mostly on servers, not on workstations infront of
which a user might sit using a desktop environment. Instead there might
only be a person which inserts a usb flash drive into a usb port on
demand with no graphical UI at all runing on this machine.

Despite the fact that the dbus ipc mechanism is not directly related to
desktop environment I wasn't yet able to find a dbus
daemon/service/listener which simply offers the possibility to start a
script stuffed with an appropriate set of environment variables fed with
the arguments of the dbus call to take appropriate actions like mounting
a file system in a suitable place.
A script because for instance we would like to start the backup of
certain filesystem areas if a certain usb external HDD or a certain usb
flash drive is inserted into a usb port - or similar things.

Does somebody know about such a program!?

Best regards
Henning
--
Can't open /usr/fortunes. Lid stuck on cookie jar.

The Natural Philosopher

unread,
Nov 16, 2021, 8:11:12 AM11/16/21
to
On 16/11/2021 12:09, Henning Hucke wrote:
> Hi everybody,
>
> I'm an admin for round about the last 25 years working with diverse
> flavours of unixoid operating systems and especially with linux.
>
> This means that I work mostly on servers, not on workstations infront of
> which a user might sit using a desktop environment. Instead there might
> only be a person which
^^^^
I admire the gender neutrality, extended to cover robots and androids..

> 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?

https://unix.stackexchange.com/questions/28548/how-to-run-custom-scripts-upon-usb-device-plug-in

might be of interest in that respect.

I last hacked that (udev) ten years ago to get inserting a camera to
'do the right thing' (linux now does it by default). The syntax is
tricky and the interface poorly documented, but the bloody thing does,
in fact, work.

--
In a Time of Universal Deceit, Telling the Truth Is a Revolutionary Act.

- George Orwell

David W. Hodgins

unread,
Nov 16, 2021, 11:55:59 AM11/16/21
to
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

Henning Hucke

unread,
Nov 18, 2021, 9:37:46 AM11/18/21
to
On 2021-11-16, David W. Hodgins <dwho...@nomail.afraid.org> wrote:


> 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 ...

Just googled 'https://networkengineer.me/2015/06/16/conceptual-understanding-of-sysfs-udev-hald-dbus/'.

I *know* that it can be done by udev but I intentionally asked for a
solution with dbus - see above.

Concerning hardware events dbus is fed/triggered by udev indeed. There
are things which make dbus attractive also for the described scenario.

Regards
Henning
--
How many bits would a BitBlit blit if a BitBlit could blit bits?
-- macan...@waves.pas.ti.com in <1993Nov16...@waves.pas.ti.com>
Reply all
Reply to author
Forward
0 new messages