LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (https://www.linuxquestions.org/questions/linux-software-2/)
-   -   How to detect programatically if a USB device is is plugged-in / plugged out? (https://www.linuxquestions.org/questions/linux-software-2/how-to-detect-programatically-if-a-usb-device-is-is-plugged-in-plugged-out-524568/)

franc 02-01-2007 12:41 AM

How to detect programatically if a USB device is is plugged-in / plugged out?
 
Hi all,

How can I programatically detect if any USB drive (say thump drive) is plugged-in or plugged out at any time?
Also get details on the device plugged-in?
Can I use udev rules to achieve this?
The goal is to get access to the contents within the program.

Thanks for your help.
Franc

shawnbishop 02-01-2007 01:19 AM

Hi

I suppose you could use the "lsusb" command, which then references to the /dev/sd... device.

Cheers

tredegar 02-01-2007 03:49 AM

I think you can do this with udev rules. See this link:
http://www.reactivated.net/writing_u...l#external-run

nx5000 02-01-2007 04:01 AM

Both method would work.
As you are using udev, you always know what will be the name of the device node in /dev.
Then this is ok (for shell scripts) :
[ -b /dev/sda ] && echo "sda present" || echo "sda not present"


All times are GMT -5. The time now is 11:26 AM.