Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using expect script for gpg - password decryption - does not work

Hi I am fairly new to expect scripting. I am trying to use the gpg for password encryption/decryption. Encryption has no issues. For Decryption, I am trying to automate it using expect script. The basic command I am trying to use is: gpg -o -d <.gpg file with encrypted password>

When I run this command, stand alone, it asks for passphrase, when I enter it, it creates the output file, as expected. The output file has password in it.

When I run this command using an expect script so that the passphrase can be provided automatically at run time, the expect does not create the output file.

Any help is appreciated. It does not show any errors! The output is:

spawn gpg -o /home/gandhipr/passwdfile -d /home/gandhipr/passfile.gpg
gpg: CAST5 encrypted data
Enter passphrase: 

Below is my expect script.

#!/usr/bin/expect
set timeout 1
set passdir [lindex $argv 0]
set passfile [lindex $argv 1]
set passfilegpg [lindex $argv 2]
set passphrase [lindex $argv 3]
spawn gpg -o $passdir$passfile -d $passdir$passfilegpg
expect "Enter passphrase:"
send "$passphrase\n"
exp_internal 1
exit 0;
interact
like image 638
Prashant Gandhi Avatar asked Sep 12 '25 01:09

Prashant Gandhi


1 Answers

Use \r instead of \n in the send command: \r is the carriage return characters which mimics the user hitting Enter.

like image 116
glenn jackman Avatar answered Sep 15 '25 16:09

glenn jackman