Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I have a small USB HD I've bought for doing daily backups, which has an encfs system on it.

I've got an autorun script in the root that does a couple of things including mounting the enc-FS and that part works fine.

However if I forget to fusermount -u the enc-FS -before ejecting it, there is no warning about anything and the USB dismounts, leaving the encFS part apparently still mounted. Of course it isn't really, and attempting to access with nautilus say, causes the machine to "behave badly".

There's also the risk of lost files I suppose.

For some reason the systems doesn't seem to detect the drive is still active as it normally does, in this scenario.

Anyway my question is, is it possible to set up the equivalent of an autorun-on-dismount that runs when the USB eject occurs?

Thanks

share|improve this question

1 Answer 1

Well I've come up with a not very elegant way to get round this. The autorun script looks something like this:

#!/bin/bash

/path/to/mount-script&

while : # loop isn't really needed ...
do
    sleep 999d # ...  because the script will idle for 999 days
    if (($?))
    then
    # sleep closed abnormally, so tidy up
        /path/to/dismount-script
         exit 1
    fi
done

So when the drive eject occurs, the system detects sleep and bash are still running and puts up the warning dialogue; right-click sleep in the dialogue and end it then causes an exit status of 130 that means the dismount script gets called and when it returns the bash script terminates and the USB device then ejects cleanly.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.