You are not logged in.

#1 2011-07-10 15:26:06

chronozphere
Member
Registered: 2011-06-18
Posts: 18

[shellscript] Passing a script with parameters to AT

Hey everybody,

I would like to learn shell scripting so I created a script to mount/unmount my truecrypt volume. This is what I have so far:

#!/bin/bash

case "$1" in
        start)
                truecrypt -k '' /dev/array/vault /home/<user>/vault
                ;;
        stop)
                truecrypt -d /home/<user>/vault
                ;;
        *)
                echo "usage: $0 (start|stop)"
esac
exit 0

Now I would like to add another feature. I want it to automatically unmount after 2 hours. I found the "at" command which should be able to do this.
I would need to do something like:

        start)
                truecrypt -k '' /dev/array/vault /home/<user>/vault
                at -f "$1 stop" now + 2 hours 
                ;;

However, running just " at -f "./vault.sh start" now + 2 minutes " fails:

warning: commands will be executed using /bin/sh
Cannot open input file ./vault.sh start: No such file or directory

If I can get this working I would like the "stop" code to remove any scheduled stop operations (for when I do it manually).  Also, I would like to include a "keepalive" function that allows me to kill the scheduled stop task and reschedule it again to restart the countdown. This would allow me to keep the volume mounted if I want to use it for a longer period of time.

Is it possible to execute scripts + parameters with "at"?  Can somebody help me to make this work?

Thanks a bunch! smile



P.S: Truecrypt also keeps asking me this:

Protect hidden volume (if any)? (y=Yes/n=No) [No]:

I would like to specify this in the command so that I don't have to hit enter every time. I've looked at the man page but found nothing helpfull. Anyone?

Offline

#2 2011-07-12 19:24:51

gadget3000
Member
Registered: 2010-05-11
Posts: 23

Re: [shellscript] Passing a script with parameters to AT

Make sure that vault.sh exists in the directory that you are executing it from. It may be better to refer to the whole file location rather than just './'. eg use " at -f "~/vault.sh start" now + 2 minutes " rather than just  " at -f "./vault.sh start" now + 2 minutes ".

Providing thatyou are happy for TrueCrypt to accept the default answer for any questions it asks you can just pipe yes into it:
yes | truecrypt -k '' /dev/array/vault ~/vault
Yes will 'press enter' to any questions that TrueCrypt asks.

Last edited by gadget3000 (2011-07-14 16:46:01)

Offline

#3 2014-08-26 15:01:03

Areopagite
Member
Registered: 2014-08-24
Posts: 1

Re: [shellscript] Passing a script with parameters to AT

Hello!

You can execute scripts + parameters with "at" this way:

echo DISPLAY=:0 ./vault.sh start | at now + 2 minutes

It works!

Offline

#4 2014-08-26 15:28:47

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 29,576
Website

Re: [shellscript] Passing a script with parameters to AT

Areopagite, please do not necrobump old threads

Neither of the users in this thread have even been on the forums in a year.

Feel free to open a new thread if you have a new question.

Closed.


"UNIX is simple and coherent..." - Dennis Ritchie, "GNU's Not UNIX" -  Richard Stallman

Offline

Board footer

Powered by FluxBB