Find the answer to your Linux question:
Results 1 to 6 of 6
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 ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined! robsku's Avatar
    Join Date
    Sep 2007
    Location
    Finland, Helsinki
    Posts
    6

    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!

  2. #2
    Linux Engineer Freston's Avatar
    Join Date
    Mar 2007
    Location
    The Netherlands
    Posts
    1,049
    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

  3. #3
    Just Joined! robsku's Avatar
    Join Date
    Sep 2007
    Location
    Finland, Helsinki
    Posts
    6
    Thank you - it's still a bit dirty, but much less than my plan... It will do, much thanks...

  4. #4
    Linux Guru bigtomrodney's Avatar
    Join Date
    Nov 2004
    Location
    Ireland
    Posts
    6,132
    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.

  5. #5
    Just Joined! robsku's Avatar
    Join Date
    Sep 2007
    Location
    Finland, Helsinki
    Posts
    6
    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!

  6. #6
    Linux Engineer Freston's Avatar
    Join Date
    Mar 2007
    Location
    The Netherlands
    Posts
    1,049
    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •