Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

problem with gpg password

25 views
Skip to first unread message

peter

unread,
Jun 18, 2006, 2:19:49 PM6/18/06
to

Hi everyone, I have a question about using expect with gpg. I'm new to
using expect and am trying to write a simple expect script to deal with
decrypting a .gpg file...
The script is:

spawn gpg -o OUTPUTFILE --yes -d GPGFILE
expect "phrase: "
send "PASSPHRASE\r"
exit

where OUTPUTFILE, GPGFILE and PASSPHRASE are replaced with the files I
want to use. when I invoke expect directly from the command line and
enter each line manually at the "expect1.x>" prompts, it works flawlessly
every time, however when I put the exact same lines into a script, it
appears to do everything, but the script exits and the gpg file is simply
never decrypted. any ideas what I'm doing wrong?
thanks!
peter

Cameron Laird

unread,
Jun 18, 2006, 3:22:07 PM6/18/06
to
In article <R7OdnUqEpZjYBAjZ...@comcast.com>,

My guess: you need to give the process time to finish, rather than
exiting immediately after delivery of PASSPHRASE. How about putting
one more [expect] before the exit?

peter

unread,
Jun 18, 2006, 5:02:13 PM6/18/06
to

cla...@lairds.us (Cameron Laird) wrote:
>My guess: you need to give the process time to finish, rather than
>exiting immediately after delivery of PASSPHRASE. How about putting
>one more [expect] before the exit?

your guess was right! it was killing gpg before it had a chance to
finish, so i had to put in another expect statement, in this case:
expect "\"$"

since a successful decryption results in a line with a double quote at
the very end of the line just before gpg exits. thanks very much for your
help!!!
best,
peter

peter

unread,
Jun 19, 2006, 1:03:56 AM6/19/06
to

in the interest of putting this solution out there in the wild so others
can benefit, here is the completed working script. (i know i looked for
a long time with no luck before finally posting my question here, and
it seems that others have tried to do similar things with similar issues
that i was running into.)
from my limited testing of it, the script seems to work consistently.
i'm guessing that there may be better or cleaner ways to accomplish this,
and that this will probably need some flow-control for it to behave
nicely in all cases. for what it's worth, the reason i wrote this script is
to that it can be called by another programs. enjoy!
-----------
#!/usr/bin/expect -f

# this script should be called with syntax:
# expect_test encryptedfile outputfile "passphrase"
# NOTE that the passphrase should be put in double quotes in case it has
any spaces
set encryptedfile [lindex $argv 0]
set outputfile [lindex $argv 1]
set the_passphrase [lindex $argv 2]

spawn gpg -o $outputfile --yes -d $encryptedfile
expect "phrase: "
stty -echo
send $the_passphrase\r
stty echo
expect "\"$"
exit
-----------

Bruce Hartweg

unread,
Jun 19, 2006, 10:42:32 AM6/19/06
to

FYI, if you really want to make sure the spawned process has exited,
you can use expect eof. That way if future/alternate versions of pgp
change chars that are output, you won't be negatively affected.

Bruce

0 new messages