Detect USB keyboard and other peripherals

Login or Register for Dates, Times and to Reply

Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Detect USB keyboard and other peripherals
# 1  
Question Detect USB keyboard and other peripherals

Hi there,

I have a Debian machine without any peripherals (no screen, no keyboard, etc.). I'd like to be able to detect and log when someone plugs a USB keyboard. Something like : 2009-07-04 12:21 warning: keyboard pluged!
Is that possible?

I see two ways :
1. Either actively react to the connection of a device and execute a script that logs the alert.
2. Or cron a script that checks for USB devices every 5 minutes.
I have no idea how to do either ways.
Can anyone help me on that?

I would be glad to just be able to alert when any USB device is plugged. No matter if it's a keyboard or a flash key. But if I can make the difference between each device type... Better!

Thanks for your help
# 2  
The obvious idea that comes to mind is to watch for messages from dmesg (or the /var/adm/messages file?) as USB devices are plugged in, it is how I normally find out what the device path for a USB stick is anyway...
# 3  
Thanks TonyFullerMalv,
I'm investigating this idea.
Though, I have no such /var/adm/ folder.
# 4  
Depending on how current your Debian installation is you might have DBUS & HAL installed. There's a command-line tool for DBUS which you can instruct to listen for added devices: (example is a flash drive)
> dbus-monitor --system --profile 'interface=org.freedesktop.Hal.Manager, member=DeviceAdded'
sig     1246865406      537113  2       /org/freedesktop/DBus   org.freedesktop.DBus    NameAcquired
sig     1246865413      849690  6387    /org/freedesktop/Hal/Manager    org.freedesktop.Hal.Manager     DeviceAdded
sig     1246865413      898142  6390    /org/freedesktop/Hal/Manager    org.freedesktop.Hal.Manager     DeviceAdded
sig     1246865414      883198  6393    /org/freedesktop/Hal/Manager    org.freedesktop.Hal.Manager     DeviceAdded
sig     1246865414      883255  6394    /org/freedesktop/Hal/Manager    org.freedesktop.Hal.Manager     DeviceAdded
sig     1246865414      903331  6403    /org/freedesktop/Hal/Manager    org.freedesktop.Hal.Manager     DeviceAdded
sig     1246865415      53744   6430    /org/freedesktop/Hal/Manager    org.freedesktop.Hal.Manager     DeviceAdded
sig     1246865415      97264   6449    /org/freedesktop/Hal/Manager    org.freedesktop.Hal.Manager     DeviceAdded

If you pipe this into a loop you should be able to detect just about any HW change.
# 5  
Originally Posted by chebarbudo
Thanks TonyFullerMalv,
I'm investigating this idea.
Though, I have no such /var/adm/ folder.
Sorry I was thinking Solaris! Try looking in /var/log/messages!

Also try taking a look at the lsusb(8) command.
Login or Register for Dates, Times and to Reply

Previous Thread | Next Thread
Thread Tools Search this Thread
Search this Thread:
Advanced Search

Test Your Knowledge in Computers #699
Difficulty: Medium
The noosphere represents the highest stage of biospheric development, its defining factor being the development of humankind's rational activities, according to biogeochemist Vladimir Vernadsky.
True or False?

9 More Discussions You Might Find Interesting

1. HP-UX

Configure X windows with both keyboard and USB barcode reader

Greetings. Seeking guidance on adding a USB barcode reader (BCR) to an HP c3750 workstation with HP-UX 11.11 which is essentially configuring X windows to accept input from both a primary keyboard and a secondary keyboard that happens to be the BCR. Historically, I have successfully added a BCR... (2 Replies)
Discussion started by: mnkaltenbach
2 Replies

2. OS X (Apple)

Detect active usb device used by app

I've searched a number of sites but thought I'd post it here. I'm want to a detect certain usb device (external camera) that is actively being used by an app on a mac. My search has led me through looking at the system events log to see if there is a ProductID indicator logged. The device is... (2 Replies)
Discussion started by: dallas88
2 Replies

3. Shell Programming and Scripting

script to detect a file from inserted usb and puts into a Variable

There is a same named log file that I have on my 2 different android phones. When I plug it into my computer, it appears in the media folder, For example the first android phone: /media/F6BA-0AF5/folder/A.log I want to put that into a variable to be manipulated.... (3 Replies)
Discussion started by: tobenguyen
3 Replies

4. Linux

How to read keys from USB keyboard on AT91SAM9260

Hi Everyone, I am using kernel(Embedded system) running on AT91SAM9260. I am using a Logitech USB keyboard. It is detected as "/dev/input/event0". I don't know how to detect key press events and read the keys? Why can't I read the keys using scanf() like funtions? ... (7 Replies)
Discussion started by: siva4ever
7 Replies

5. Shell Programming and Scripting

BASH Script to Detect and List USB Flash Drives

Hello. This is my first post to this forum. I've read many of the posts over the last two or three years and I've learned a lot. I'm creating a live Linux distribution using the Linux Live Scripts -- just as a hobby project -- and I'm wanting to create an automated way for a user to copy the... (7 Replies)
Discussion started by: godzillarama
7 Replies

6. Programming

How to detect usb storage arrival and its mount path from C

Hi, I am a newbi to linux, i wana to write a program in C that can detect arrival of a usb flash memory. I want also to find the actual mount point of new inserted flash disk. can anyone help me? thanks a lot (6 Replies)
Discussion started by: aghashahi
6 Replies

7. UNIX for Dummies Questions & Answers

Can't detect usb thumbdrive anymore

hey everyone! i have a Solaris 8 box with me, and i had been using my usb thrumbdrive on it all the time. one day, i was in a rush and i pulled out the thumbdrive without ejecting it or anything. and now i can't detect any thumbdrives at all. i had tried using another thumbdrive, but with no... (2 Replies)
Discussion started by: feef
2 Replies

8. UNIX for Dummies Questions & Answers

USB keyboard in Solaris

I have a USB keyboard/mouse combo hooked up to an x86 box and when it loads the mouse works fine, but the ctrl, shift, alt, and i think the function keys don't do anything. Is there a setting I need to change, or a way to manually configure them. There are no drivers, it is supposed to emulate a... (0 Replies)
Discussion started by: Winzernotman
0 Replies

9. Programming

mont of peripherals

hello i'm working on redhat linux which is installed with windows on the same hard disk i would like to get access to windows files throw linux the question is: how to mount hard disk and peripherals ? think you (0 Replies)
Discussion started by: selim
0 Replies

Featured Tech Videos