Score:0

Detecting if any device is being plugged in

hu flag

Hi I wanted to write a script that ran whenever any device was plugged in. If found How to detect an USB device? for usb ports. And How can I run a script when the power supply is plugged-in or -out? for powersupply, for powersupply however only featured if it was plugged in and then contounsly preformed an action. I need a script to run once whenever something is plugged in. Is there anyway to do this?

waltinator avatar
it flag
Watch `sudo journalctl --follow` as you connect your devices. There's a system, called `udev` that notices when device events happen. Read `man udev`, and `man -k udev`.
Jip Helsen avatar
hu flag
@waltinator thx! If you where to write an answer with an example script, I will approve and upvote. If not thx for the usefull tip!
waltinator avatar
it flag
Sorry, writing `udev` rules (not scripts) for a remote system, with unknown hardware, is not something that's easy. I won't. It's up to you to learn about `udev`, look at `udev` on your system, search for `udev` tutorials on the web, ... Don't fall victim to UTBLT! (Using Tool Before Learning Tool).
Jip Helsen avatar
hu flag
Yeah thx, true that. It is easy to falling in to thinking learning something is just a trivial step in accomplishing your goal. I will have a look at it when I have the time, but in retrospective do not need to check all the inputs, yielding this question rather useless. But thx some great dev wisdom I all to often forget :)!
I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.