I'm mounting a truecrypt container via the command line (i.e. truecrypt file dir). Is there any way to have truecrypt automatically unmount the container after a given amount of inactivity in dir?
- 807,993
- 194
- 1,674
- 2,175
- 9,184
- 13
- 65
- 106
-
That's a job for an automounter. Last time I used one on Linux, they kind of sucked, but I think they've improved in the last decade. – Gilles 'SO- stop being evil' Sep 05 '12 at 22:25
-
@Gilles Thanks for pointing it out, I'll try and find one for this – Tobias Kienzler Sep 06 '12 at 06:04
-
Can `truecrypt` be mounted with the `mount` command? – Nils Sep 06 '12 at 21:24
-
Could you perhaps use something similar to @ultrasawblade's script and leverage `lsof` (or possibly /proc/*/fd or somesuch; lsof gets its data from *somewhere*...)? It wouldn't be perfect (very fast accesses would go uncaught, and it would cause a bit of CPU hammering), but I'm guessing it's either something like that, or access notifies (which at the very least means write a system application, not a script). – user Jan 04 '13 at 12:40
1 Answers
Truecrypt can't do this but something like the following would accomplish what you are trying to do:
#!/bin/bash
TIMEOUT_PERIOD_IN_MINUTES=60
cd /
sleep ${TIMEOUT_PERIOD_IN_MINUTES}m
echo "$0: Proceeding with dismount in 5 minutes." > /dev/console
# or something else to notify user that the volume will be unmounted
sleep 4.5m
echo "$0: Proceeding with dismount in 30 seconds." > /dev/console
sleep 30s
sync; truecrypt $@
The cd / would be to ensure that the current directory is never within the mounted truecrypt volume, just in case you invoked it under different circumstances.
Save this somewhere, chmod +x it, and call it something like truecrypt-auto-dismount, and then
truecrypt {mount-options}; truecrypt-auto-dismount {dismount-options}
I would definitely incorporate some type of notification so you have a chance to close open files. Of course you could get rather elaborate and try to incorporate a loop that kills with SIGTERM (and then does SIGKILL if it doesn't respond in a timeframe) all processes listed by lsof | grep /mnt/your-truecrypt-volume if you wanted.
- 10,884
- 4
- 33
- 45
-
Thanks, that's a general timeout, but I'm looking for a possiblity to have the timer reset whenever the mounted `dir` is accessed again. And http://www.truecrypt.org/docs/?s=background-task suggest that this is possible when using the GUI (which I can't) – Tobias Kienzler Sep 05 '12 at 14:39