LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 02-01-2007, 12:41 AM   #1
franc
LQ Newbie
 
Registered: Dec 2004
Posts: 1

Rep: Reputation: 0
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
 
Old 02-01-2007, 01:19 AM   #2
shawnbishop
Member
 
Registered: Dec 2005
Location: South Africa
Distribution: CentOS,Ubuntu,Fedora
Posts: 249

Rep: Reputation: 30
Hi

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

Cheers
 
Old 02-01-2007, 03:49 AM   #3
tredegar
LQ 5k Club
 
Registered: May 2003
Location: London, UK
Distribution: Fedora38
Posts: 6,147

Rep: Reputation: 435Reputation: 435Reputation: 435Reputation: 435Reputation: 435
I think you can do this with udev rules. See this link:
http://www.reactivated.net/writing_u...l#external-run
 
Old 02-01-2007, 04:01 AM   #4
nx5000
Senior Member
 
Registered: Sep 2005
Location: Out
Posts: 3,307

Rep: Reputation: 57
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"
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Help mounting USB flash drive ... When plugged in I dont have /dev/sda1 device ... ebenh Ubuntu 2 09-17-2006 09:55 PM
usb device works only when is plugged in after booting Jaa Linux - Hardware 2 08-22-2006 10:00 AM
how to know a usb device is plugged in/out lordofring Linux - Software 2 04-25-2005 01:15 PM
Why does PC hang when USB device is plugged in? DeepSPiN Fedora 1 12-03-2003 10:59 AM
System freezes during boot with USB device plugged in. dhrivnak Slackware 3 10-31-2003 08:55 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 01:05 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration