Linux Archive

Linux Archive (http://www.linux-archive.org/)
-   CentOS (http://www.linux-archive.org/centos/)
-   -   Detect if a drive is USB? (http://www.linux-archive.org/centos/706206-detect-if-drive-usb.html)

Lists 09-21-2012 06:36 PM

Detect if a drive is USB?
 
I'm updating a script to work with EL6 (previously worked on EL5) and am
stumped, google fu is failing me. Part of the script is to detect USB
drives and mount them. Previously, It worked something like

isUsbDevice() {
if [ -f /sys/block/$1/usb ] ; then
// do stuff
fi;
}

but I don't find the "usb" file/directory anywhere to be found any more
on el6. I've tried the output of lsusb and lsusb -v but in no case have
I been able to find anything there matching anything in /sys/block that
matching anything in lsusb's output.

Given an available drive (EG: /dev/sdk) how can I reliably tell it's
interface type? (USB/SATA/PATA/SCSI ?)


_______________________________________________
CentOS mailing list
CentOS@centos.org
http://lists.centos.org/mailman/listinfo/centos

Lists 09-21-2012 07:31 PM

Detect if a drive is USB?
 
Answering my own message for posterity's sake: This line will output "E:
ID_BUS=usb" for any block
device connected to a USB bus:

udevadm info --query=all --name=$file 2>/dev/null | grep -i BUS=usb;

The basic idea is to
1) use udevadm to get all info on device $file (where $file is a string
like "sde")
a) send all errors to /dev/null.
2) grep the output of udevadm for the string "BUS=usb" which appears on
USB devices.

Note that you must have $file defined with a device name which I got by
listing the contents of /sys/block.

Good luck! Also, if anybody has a better solution, please reply. The
above appeared to be "good enough"
to finish porting my admin script.

-Ben

On 09/21/2012 11:36 AM, Lists wrote:
> I'm updating a script to work with EL6 (previously worked on EL5) and am
> stumped, google fu is failing me. Part of the script is to detect USB
> drives and mount them. Previously, It worked something like
>
> isUsbDevice() {
> if [ -f /sys/block/$1/usb ] ; then
> // do stuff
> fi;
> }
>
> but I don't find the "usb" file/directory anywhere to be found any more
> on el6. I've tried the output of lsusb and lsusb -v but in no case have
> I been able to find anything there matching anything in /sys/block that
> matching anything in lsusb's output.
>
> Given an available drive (EG: /dev/sdk) how can I reliably tell it's
> interface type? (USB/SATA/PATA/SCSI ?)
>
>
> _______________________________________________
> CentOS mailing list
> CentOS@centos.org
> http://lists.centos.org/mailman/listinfo/centos
>

_______________________________________________
CentOS mailing list
CentOS@centos.org
http://lists.centos.org/mailman/listinfo/centos


All times are GMT. The time now is 12:54 PM.

VBulletin, Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.