Score:0

Run Command When USB Device Connected

in flag

I have a USB flash drive plugged in to my Ubuntu Server machine most of the time. It has an entry in /etc/fstab which mounts it to /mnt/foo after being identified by UUID. It mounts fine on boot and when

sudo mount -a

is run. But, if I disconnect and reconnect the device [physically], it'll be recognised (as in shown in lsblk), but not mounted.

I have a backup script that copies files to /mnt/foo, so it needs to be mounted there as soon as it's connected. How do I mount this USB automatically when it's connected (and on boot)?

lucki1000 avatar
us flag
You can make Cron job(as root) who runs `mount -a` all 5mins
toydotgame avatar
in flag
@lucki1000 I would rather not run a command on a loop in the background. Primarily because I'd like it to be mounted as soon as the drive is plugged in.
waltinator avatar
it flag
Read `man -k udev`. `udev` is designed to make this kind of task (recognize a particular USB and Do Something) "easy".
toydotgame avatar
in flag
@waltinator I've tried making udev rules before. The syntax and all is correct, but nothing works. Is there something I'm missing?
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.