Reputation: 41
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
Upvotes: 4
Views: 6189
Reputation: 247102
Use \r
instead of \n
in the send command: \r
is the carriage return characters which mimics the user hitting Enter.
Upvotes: 3