You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I wrote a script that get's mount point and label as parameters and creates a symlink to all musik files on the usb drive in a subfolder in my mpd musik directory, named after the label of the drive. It is executed with devmons exec on drive feature and everything works fine.
Now I want to delete all the symlinks again when the stick is removed, but when I have devmon start a script with exec on remove it does not provide a value for %l. Using on unmount is not an option because I am on a headless machine and most of the time usb drives will not be unmounted before they are removed.
Is there any option or workaround to get the result I am looking for?
The text was updated successfully, but these errors were encountered:
devmon doesn't cache the device info, it just reads it via libudev (via udevil or udisks) and reports it in real time. So after the device is removed, there is no device label to be read. udev only reports what device was removed.
To make it work this way, one could edit the devmon script so that it stores volume labels in an array, such that when a device is removed it can lookup the corresponding label.
Another possibility would be for your exec-on-drive command to read and save the volume label to a temp file with a name corresponding to the device name. Then when the device is removed, your exec-on-remove command could read the most recent label corresponding to that device from that file.
You could also include the volume label and device name in the name of the symlinks you create, so your script can remove them by device name. For example, name the symlink "sdd1-My Label", or "My Label-dev-sdd1". Then you could delete "sdd1-" or "-dev-sdd1" when you see sdd1 removed.
I'll leave this open as a request, though this is a fairly specialized use so is unlikely to be implemented in devmon.
Thanks for the Info. I don't think that devmon should save this information on his own, because that would generate overhead which is unnecessary for most people. A notice in the documentation however, that mount point and label are not available for exec-on-remove calls would have saved me some debugging time ;)
I used A file now to store the label and device name and look it up later. Here is the code I used in case someone else trying to do something similar ands up on this page:
In the onMount script:
# put name and label in a file to look up later
file=/tmp/usbmountlabels.tmp
echo$name>>$fileecho$label>>$file
in the onRemove script:
#find the label in the temp file and delete them there
file="/tmp/usbmountlabels.tmp"
found=false
whileread -r line
doif [ $found=true ]
then
label="$line"
found=false
elif [ "$line"="$name" ]
then
found=true
elseecho"$line"fidone<"$file">"/tmp/o.tmp"
mv "/tmp/o.tmp""$file"
This worked for me, but I only tested with one flash drive, so use at own risk.
I wrote a script that get's mount point and label as parameters and creates a symlink to all musik files on the usb drive in a subfolder in my mpd musik directory, named after the label of the drive. It is executed with devmons exec on drive feature and everything works fine.
Now I want to delete all the symlinks again when the stick is removed, but when I have devmon start a script with exec on remove it does not provide a value for %l. Using on unmount is not an option because I am on a headless machine and most of the time usb drives will not be unmounted before they are removed.
Is there any option or workaround to get the result I am looking for?
The text was updated successfully, but these errors were encountered: