Welcome to Linux Forums! With a comprehensive Linux Forum, information on various types of Linux software and many Linux Reviews articles, we have all the knowledge you need a click away, or accessible via our knowledgeable members.
Find the answer to your Linux question:
New to Linux Forums? Register here for free!
    Linux Forums > GNU Linux Zone > Misc > Identify USB stick insert/removal and lock/unlock screen...

Forgot Password?
 Misc   Any questions or Linux discussion that does not fit in any of the other technical areas.

Site Navigation
Linux Articles
Linux Forums
Linux Downloads
Linux Hosting
Free Magazines
Job Board
IRC Chat
RSS Feeds


Linux Forum Topics
Linux Forums
Your Distro
Linux Resources
GNU Linux Zone
The Community
Reply
 
Thread Tools Display Modes
Old 09-26-2007   #1 (permalink)
Just Joined!
 
robsku's Avatar
 
Join Date: Sep 2007
Location: Finland, Helsinki
Posts: 5
Send a message via MSN to robsku
Cool Identify USB stick insert/removal and lock/unlock screen...

Hi - I want a system that locks my X display (using xscreensaver) when I remove my USB stick and automatically unlocks it when I remove my usb stick.

I'm planning to create a shell script running in constant loop and sleeping for a few seconds everytime in the end of loop - unless I have to use a way where that wont work...

The big problem is reacting to insert/removing the usb stick...

And then recognizing the usb stick to be the correct one without mounting it if possible - this way I guess it could be any USB device...

Smaller problem is how to unlock the xscreensaver... it could just be killed and restarted.

So far the best plan (and it's not that good) I have come up with is to watch fstab, as the usbstick's mount point and parameters are added there automatically when plugged in and removed when taken off and react according to it... It's very quick and dirty solution, but it get's worse...

To identify the usb-stick I don't know a way without mounting it and I dont want to mount it automatically, so I came up with another quick and dirty solution - when usb-stick is inserted it quickly mounts it, checks if certain data is saved there and unmounts it - and unlocks/kills&restarts the screensaver if it is the correct stick.

I would really wish to have a better solution than this, but it could work at least. Any help for not so... lame solution is highly appreciated!
robsku is offline  


Reply With Quote
Old 09-26-2007   #2 (permalink)
Linux Engineer
 
Freston's Avatar
 
Join Date: Mar 2007
Location: The Netherlands
Posts: 826
Welcome!


The simple solution is loop&sleep a script filtering <lsusb> to grep certain identifiable info. That way you don't need to mount.

It's a dirty solution, but it works

To unlock just kill the screensaver. Be sure to have the sleep timer a LOT shorter when the USB is removed than when the USB is inserted. When you are away (USB removed) all your machine has to do is fanatically cycle through lsusb looking for your return (USB inserted).

---

I did the same on my machine, but instead of looking for a certain USB device it measures the distance to my mobile phone using Bluetooth. All I need to do to lock my computer is to walk away from it, and to unlock it I just have to come close again
__________________
Can't tell an OS by it's GUI
Freston is offline   Reply With Quote
Old 09-26-2007   #3 (permalink)
Just Joined!
 
robsku's Avatar
 
Join Date: Sep 2007
Location: Finland, Helsinki
Posts: 5
Send a message via MSN to robsku
Thank you - it's still a bit dirty, but much less than my plan... It will do, much thanks...
robsku is offline   Reply With Quote
Old 09-26-2007   #4 (permalink)
/etc/init.d/moderator
 
bigtomrodney's Avatar
 
Join Date: Nov 2004
Location: Sunny South-East of Ireland
Posts: 6,031
You could look at udev and see if you could create a rule for an application to run when a certain device is inserted. The problem may be that it is specific to a device, or that it may replace the automount of the device - but nonetheless udev is specifically designed for reacting to device plugging/unplugging.
__________________
Registered Linux user #378740
New members read here / Forum Rules
#linuxforums on irc.freenode.net
bigtomrodney is offline   Reply With Quote
Old 09-26-2007   #5 (permalink)
Just Joined!
 
robsku's Avatar
 
Join Date: Sep 2007
Location: Finland, Helsinki
Posts: 5
Send a message via MSN to robsku
Quote:
Originally Posted by Freston View Post
I did the same on my machine, but instead of looking for a certain USB device it measures the distance to my mobile phone using Bluetooth. All I need to do to lock my computer is to walk away from it, and to unlock it I just have to come close again
I just had to add one more reply - didn't notice this part of your message.

It just seems that I owe you a big thanks, because I don't think there are many programs made for this particular purpose. You see, I got the idea for this when I bumped into a webpage with a program to do just that (lock/unlock by measuring bluetooth devices distance) and decided to do this. Certainly it must be your work that gave me the idea =) Small world!
robsku is offline   Reply With Quote
Old 09-27-2007   #6 (permalink)
Linux Engineer
 
Freston's Avatar
 
Join Date: Mar 2007
Location: The Netherlands
Posts: 826
Thnx! But I'm afraid I must decline the honor. Browsing the Gentoo wiki I found an article that gave me the inspiration for the said script. I'm afraid my dull understanding has yet to produce anything bright, pertinent or imaginative.

... as of yet, I add, as of yet ...
__________________
Can't tell an OS by it's GUI
Freston is offline   Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

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 On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off

Free Magazines
Run Your Own Web Server Using Linux & Apache - Free 191 Page Preview
Learn about everything you'll need to build and maintain your Linux servers, and to deploy Web applications to them.
subscribe
Open Source Security Myths Dispelled
Dispel the five major myths surrounding Open Source Security and gain the tools necessary to make a truly informed decision for your IT organization
subscribe
InformationWeek
InformationWeek is the only newsweekly you'll need to stay on top of the latest developments in information technology.
subscribe



All times are GMT. The time now is 11:07 AM.






© 2000 - 2009 - All Rights Reserved - Property of  MAS Media

Content Relevant URLs by vBSEO 3.3.0 RC2