How to uniquely distinguish between two USB ports??

Hi all,

I am facing a problem while writing a shell script.

My machine has two USB ports- left port and right port.

whenever I connect USBS to both the ports, entry is generated as /sys/block/sdc and /sys/block/sdd and I mount the USBs to a particular directory.

But I need to know which one is connected to the left and which one is connected to the right port.

For ex. Whether /sys/block/sdc is connected to the left port or /sys/block/sdd is connected to the left port.

Please give some suggestions in this regard and if you face any prolem understanding the issue please feel free to ask me.

Thanks in Advance,

PKumar Sachin

Sometimes the ports are wired together, so there is no difference. USB is, after all, 4 wires: gound, +5v, data out and data in. If they are different usb adapters, maybe this will help: An Overview of Linux USB | Linux Journal

Is your system Linux? udev provides convenient symlinks for this on many systems:

# when plugged into one port
$ ls -l /dev/disk/by-path/ | grep usb
lrwxrwxrwx 1 root root  9 Apr 14 10:43 pci-0000:00:02.1-usb-0:2:1.0-scsi-0:0:0:0 -> ../../sdd
lrwxrwxrwx 1 root root 10 Apr 14 10:43 pci-0000:00:02.1-usb-0:2:1.0-scsi-0:0:0:0-part1 -> ../../sdd1
lrwxrwxrwx 1 root root 10 Apr 14 10:43 pci-0000:00:02.1-usb-0:2:1.0-scsi-0:0:0:0-part2 -> ../../sdd2
# when plugged into another port
$ ls -l /dev/disk/by-path/ | grep usb
lrwxrwxrwx 1 root root  9 Apr 14 10:46 pci-0000:00:04.1-usb-0:1:1.0-scsi-0:0:0:0 -> ../../sdd
lrwxrwxrwx 1 root root 10 Apr 14 10:46 pci-0000:00:04.1-usb-0:1:1.0-scsi-0:0:0:0-part1 -> ../../sdd1
lrwxrwxrwx 1 root root 10 Apr 14 10:46 pci-0000:00:04.1-usb-0:1:1.0-scsi-0:0:0:0-part2 -> ../../sdd2

If you check the udev rules that created these symlinks you can find out how udev gleans this information when creating them and make a rule that automounts for you perhaps.

thanks mates for ur suggestions.

I came to know that every port can be uniquely identified using a set of numbers, namely major number and minor number.

The major number corresponds to the USB controller and minor number corresponds to the USB device.