Results 1 to 4 of 4
Hi all,
I need to develop a SW in which the SW has to determine when any USB is connected,it has to identify and do the Read and write operation ...
- 04-20-2009 #1Just Joined!
- Join Date
- Apr 2009
- Posts
- 2
USB Pendrive Detection
Hi all,
I need to develop a SW in which the SW has to determine when any USB is connected,it has to identify and do the Read and write operation with the pendrive.
I have to identify the moment when pendrive is connected.System has no GUI only Black Box.
Im using RHEL with Kernel 2.6.18.
My question is how to identify if pendrive is connected.Is any System flag or some other thing will set In OS or we have to register for any USB related Event?
Please help me out to solve this problem
Many Thanks in Advance
Yuvi
- 04-20-2009 #2Linux Guru
- Join Date
- Apr 2009
- Location
- I can be found either 40 miles west of Chicago, or in a galaxy far, far away.
- Posts
- 8,974
The lsusb command will show you what is connected to the system. I suppose you could poll that and detect when the device list changes. A Q&D solution for sure, but something that a cron job script or just a script could do, and then automount the device if you want. A poll period of a couple of seconds would give you a reasonable response of insert-and-mount for the drive. You would still need to determine which entry in /dev corresponded to the inserted drive so you could mount it.
Sometimes, real fast is almost as good as real time.
Just remember, Semper Gumbi - always be flexible!
- 05-06-2009 #3Just Joined!
- Join Date
- Apr 2009
- Posts
- 33
usb connected
[QUOTE=gyuvarajan;687935]Hi all,
I need to develop a SW in which the SW has to determine when any USB is connected,it has to identify and do the Read and write operation with the pendrive.
I have to identify the moment when pendrive is connected.System has no GUI only Black Box.
Im using RHEL with Kernel 2.6.18.
My question is how to identify if pendrive is connected.Is any System flag or some other thing will set In OS or we have to register for any USB related Event?
Whenever I plug in a usb stick or hard drive or an sd card I always do that
(I wait a few seconds then)
# cat /proc/partitions
I have an internal sata hard drive (/dev/sda)
so if anything like
sdb1
sdb2
....
sdc1
etc.
you could of course pipe a grep
# cat /proc/partitions | grep 'sd[a-z]'
appears I know it's ready and I can mount it
As for the sd card it used to be the same but recently it's been changed
to some other name (like /dev/mmsomething, I'll have to check)
For instance on my machine if I
# cat /proc/partitions
here's what I get (I inserted a usb key before that)
major minor #blocks name
8 0 312571224 sda
8 1 73400953 sda1
8 2 10064896 sda2
8 3 100004451 sda3
8 4 1 sda4
8 5 4008186 sda5
8 6 80011701 sda6
8 7 15735636 sda7
8 8 15735636 sda8
8 9 13607023 sda9
8 16 1974272 sdb
8 17 1974240 sdb1
So, I know I can access my key at /dev/sdb1
- 05-06-2009 #4Linux Guru
- Join Date
- Apr 2009
- Location
- I can be found either 40 miles west of Chicago, or in a galaxy far, far away.
- Posts
- 8,974
USB drives appear as /dev/sdXN where X is the device letter and N is the partition number. It also appears in /proc/partitions that way - at least in my CentOS/RHEL 5.x system with the 2.6.18 kernel as well. My currently mounted USB drive is /dev/sdj1 and shows as sdj/sdj1 in /proc/partitions.
Sometimes, real fast is almost as good as real time.
Just remember, Semper Gumbi - always be flexible!


Reply With Quote