嗨,我对脚本编写还很陌生。我正在尝试使用 gpg 进行密码加密/解密。加密没有问题。对于解密,我正在尝试使用期望脚本使其自动化。
我尝试使用的基本命令是: gpg -o -d <.gpg file with encrypted password>
当我单独运行这个命令时,它会要求输入密码,当我输入它时,它会按预期创建输出文件。输出文件中有密码。
当我使用 expect 脚本运行此命令以便可以在运行时自动提供密码时,expect 不会创建输出文件。
任何帮助表示赞赏。它没有显示任何错误!输出是:
spawn gpg -o /home/gandhipr/passwdfile -d /home/gandhipr/passfile.gpg
gpg: CAST5 encrypted data
Enter passphrase:
以下是我的期望脚本。
#!/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
最佳答案
使用 \r
而不是 \n
在发送命令中:\r
是模仿用户按 Enter 的回车符。
关于encryption - 对 gpg 使用 expect 脚本 - 密码解密 - 不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8061018/