I'm trying to build a system that will remount a USB drive when plugged in.
The USB, when plugged in, is then mapped to something like /dev/sdc1
. I then want to unmount, then remount using pmount
(in order to get user permissions, so another program can read/access the USB drive). The following commands I have been running manually:
sudo umount /dev/sdc1
pmount /dev/sdc1 some_label
I then have another program that will read the files from /media/some_label
.
However, this needs to be done programmatically. I have created the following udev rule:
ACTION=="add", \
ATTRS{idVendor}=="154b", \
ATTRS{idProduct}=="00ed", \
RUN+="/usr/bin/bash /home/some/script/location/script.sh"
I know it's being run because I can change the run command to mkdir
and I see the (test) directory is created when I plug in my USB.
However, I'm unsure of how to find the device path (/dev/sdc1
) programmatically in a shell script. With that, I'm able to run those 2 commands I listed above.
Any suggestions?