Stoomy has asked for the wisdom of the Perl Monks concerning the following question:
I think I've got most every thing working except I'm not able to set the home dir. The result is the import tries to create /root/.gnupg...which fails due to perms (as it should).
If this were a straight expect script, it would look like:
set home "/home/username"
If I were doing this manually, it would look something like this:
su - <user> gpg --import ./.pgp/pubring.pkr (gpg asks if I'm sure (y/n), I say, "y") (gpg then asks for a passphrase and I enter it). then ~/.gnupg is created by gpg for <user>
Here is the relevant bit of code:
my $exp = new Expect; $exp->spawn("sudo -u $user gpg --import $home/.pgp/secring.skr"); $exp->send("set home $home\n"); #THS DOESN'T WORK...just an example of + something i tried $exp->expect(5, [qr'\(y/N\)\s*' , sub {my $exph = shift; print $exph " +y\r" ;exp_continue; }], [qr'passphrase:\s*' , sub {my $exph = shift; print $ +exph "$passphrase";exp_continue; }], [EOF => sub {die "Error: Could not login!\n"; }], [timeout => sub {die "Error: Could not login!\n"; }] +, '-re', '\$');
I'm not sure if doing sudo is the right approach or not....any suggestions much appreciated.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: perl Expect; "set home"
by Fletch (Bishop) on May 18, 2011 at 17:08 UTC | |
by Stoomy (Novice) on May 18, 2011 at 18:21 UTC | |
|
Re: perl Expect; "set home"
by flexvault (Monsignor) on May 18, 2011 at 16:29 UTC |