Find out if USB device is connected. Ruby in Linux

I'm using Ruby 1.8 and linux (Ubuntu and SLAX), and i need to write a script in ruby which finds out if some specific usb device is connected to the system and on which USB port (0,1,2, etc). It was done before with the help of HAL (hal-find-by-capability --capability serial), but now i can't use this approach. I was trying to read /var/log/messages file trying to find the number of the usb port, but it appears that this number may not be written in some systems. Other thing i tried is to check /dev folder and search for ttyUSB# file, but it doesn't appear on some system when new device connects to USB. I would appreciate any ideas how to do this.

Answers


lsusb is a linux command for displaying your usb hubs and listing the devices that are connected to them. In ruby I believe you'd be able to do something like this:

ls_results = `lsusb`

You should be able to parse that for whatever device you're looking for.


Need Your Help

How to find the next SQL Server Replication Statement

sql-server sql-server-2008-r2 replication

I am debugging my database and I am finding that the replication is failing on a delete statement.

How to iterate over two lists - python

python gtk pygtk

Hey guys. I'm trying to do something in pyGTk where I build a list of HBoxes: