I'm working with mass testing and duplication of USB flash memory on Linux.
The script I wrote for this stores paths to /dev/disk/by-path to detect if a device was plugged into a specific USB port - this way the user can connect what is displayed to what is physically present on the desk.
Sometimes a problem occurs when multiple symlinks in /dev/disk/by-path point to the same /dev/sd* device file - creating confusing results - for example the user inserts a device into port A, and ports A,B,C and D report inserted devices, while the user can see that these ports are physically empty.
I've created a one-liner that can check if this condition occurs:
file /dev/disk/by-path/* | grep -v "broken symbolic link" | cut -d'/' -f7 | sort | uniq -D | wc -l
This will return number of duplicated link destinations in /dev/disk/by-path.
It should return zero at all times.
Is there a way I can fix this without rebooting the system?
I've also asked a possibly related question: Broken links in /dev/disk/by-path