How to uniquely distinguish between two USB ports??


 
Thread Tools Search this Thread
Top Forums UNIX for Advanced & Expert Users How to uniquely distinguish between two USB ports??
# 1  
Old 04-14-2011
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
# 2  
Old 04-14-2011
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
# 3  
Old 04-14-2011
Is your system Linux? udev provides convenient symlinks for this on many systems:
Code:
# 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.
# 4  
Old 04-16-2011
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.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. SCO

Distinguish between file systems

Hello, is there any command in SCO unix by which I can check if the file system is HTFS or DTFS? Thanks (1 Reply)
Discussion started by: Mick
1 Replies

2. Linux

nix User Access Restrictions to Network, USB ports, PCMCIA, CDROM

How to create a user account on a Linux desktop machine with restrictions on connecting to the LAN, WAN, PCMCIA ports, Firewire, CDROM and generally any user controllable output options? I have the task to set up a machine for users working with sensitive data that should not be leaving the... (1 Reply)
Discussion started by: netfreighter
1 Replies

3. UNIX for Advanced & Expert Users

how to distinguish entry/exit of a syscall when using ptrace?

Hi all, I am using ptrace to keep track of clone syscalls in a program. However, I found that the traced syscall cant be paired. for example, there are some syscalls that have entry, but without exit showing up in the traced sequences. So, is there anyway to distinguish the entry and exit of a... (0 Replies)
Discussion started by: tristartom
0 Replies

4. Programming

what is the distinguish between gmake and make?

I am working on solaris 9. and use gmake to compile and linke c/c++ program. anybody can tell me the distinguish between gmake and make? :confused: (10 Replies)
Discussion started by: robin.zhu
10 Replies

5. HP-UX

how to distinguish different files while ftp?

how to distinguish different files and choose a mode while ftp?means which modes ascii or binary for zip(.gz) ,.txt,.sh,.dat and executable as well as movie files. (1 Reply)
Discussion started by: megh
1 Replies

6. UNIX for Dummies Questions & Answers

USB Ports

I want to map out specific USB ports. For example if there are 7 ports on a USB hub I want to be able to identify port #2 and send a file there. How does UNIX see these ports? (1 Reply)
Discussion started by: eggfoot
1 Replies

7. UNIX for Dummies Questions & Answers

How to Sort Records Uniquely?

I have a file containing many records separated by a % that I would like to sort uniquely (and if possible with a count of dupes) while maintaining the integrity of each record. File looks like this: % srcip: 5.6.7.8 srcburb: internal dstip: 1.2.3.4 dstport: 2000 dstburb: external... (12 Replies)
Discussion started by: earnstaf
12 Replies

8. AIX

distinguish the extension of a file

Hello, In a script shell, I have a variable containing the name of a file and I would like to distinguish the name from the extention of the file. For example, the file 'myfile.txt' is in a variable called $VAR. How can I obtain 2 variables, one with 'myfile' and the other with 'txt' ? Thank you (2 Replies)
Discussion started by: tbeghain
2 Replies

9. Programming

how to find usb ports programmatically

I need to find out where a usb flash memory drive is mounted. I have used prtconf and iostat to find the information and then used popen to parse the information to find what i need. I am wondering if there are some generic functions such as ddi_ or usb_ that i can use to find such info. I would... (1 Reply)
Discussion started by: jtcoelho
1 Replies

10. Shell Programming and Scripting

One Last Question about Core Files (distinguish) URGENT

now, what do you define as core files. there are some files outthere with the name perl.core, I-core.png, core.png I mean, are these classified as core files too??? i thought core files are simply files called "core". Please help me out this is urgent (2 Replies)
Discussion started by: TRUEST
2 Replies
Login or Register to Ask a Question