LinuxQuestions.org
Go Job Hunting at the LQ Job Marketplace
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, 01: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, 02: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, 04:49 AM   #3
tredegar
LQ 5k Club
 
Registered: May 2003
Location: London, UK
Distribution: Debian "Jessie"
Posts: 6,038

Rep: Reputation: 373Reputation: 373Reputation: 373Reputation: 373
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, 05:01 AM   #4
nx5000
Senior Member
 
Registered: Sep 2005
Location: Out
Posts: 3,307

Rep: Reputation: 53
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


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 10:55 PM
usb device works only when is plugged in after booting Jaa Linux - Hardware 2 08-22-2006 11:00 AM
how to know a usb device is plugged in/out lordofring Linux - Software 2 04-25-2005 02:15 PM
Why does PC hang when USB device is plugged in? DeepSPiN Fedora 1 12-03-2003 11:59 AM
System freezes during boot with USB device plugged in. dhrivnak Slackware 3 10-31-2003 09:55 PM


All times are GMT -5. The time now is 10:54 AM.

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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration