我正在编写一个脚本来自动在 PowerDNS 中加密(这是一个在 debian 上运行的简单 bash shell 脚本)
Certbot 运行并调用脚本,向其提供变量:$CERTBOT_VALIDATION
我已经读过一个主题了这里这表明需要'"content"'
– 注意单引号 '
和双引号 "
。 (我在代码的不同迭代中尝试过这一点,但无济于事)我正在努力输出引号内的扩展变量,这是我尝试的一种方法:
pdnsutil add-record Example.com _acme-challenge txt 120 "\"%s\"" "$CERTBOT_VALIDATION"
但是,要从 bash 输出该内容,我必须\
在"
.
我希望输出命令如下:
pdnsutil add-record Example.com _acme-challenge txt 120 "content"
做这个的最好方式是什么?
当前输出的任何内容都出现错误:
Error: Parsing record content (try 'pdnsutil check-zone'): Data field in DNS should start with quote (") at position 0 of ''yXtgt_2vlnrF7j2V-eTJZuSjXbswsGN97TQ0Zp3IynM''
答案1
我将提供更新作为将来遇到此问题的任何人的潜在答案。
运行 certbot 命令时:
certbot certonly --manual --preferred-challenges=dns --manual-auth-hook /etc/letsencrypt/customScripts/authenticator.sh -d *.example.com --dry-run
脚本authenticator.sh现在是:
#!/bin/bash
new='"'
new2=$new$CERTBOT_VALIDATION$new
pdnsutil add-record example.com _acme-challenge txt 120 $new2
echo $new2 > output.log
# Sleep to make sure the change has time to propagate over to DNS
sleep 25
这是有效的,将变量连接为字符串以添加双引号。 output.log 显示变量是
cat output.log
"RipQQbHO5pG95nzJjouCgTXJMrGTbLKQ5XsV5Zgn7uI"
和 certbot 报告:
certbot certonly --manual --preferred-challenges=dns --manual-auth-hook /etc/letsencrypt/customScripts/authenticator.sh -d *.example.com --dry-run
Saving debug log to /var/log/letsencrypt/letsencrypt.log
Plugins selected: Authenticator manual, Installer None
Obtaining a new certificate
Performing the following challenges:
dns-01 challenge for example.com
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NOTE: The IP of this machine will be publicly logged as having requested this
certificate. If you're running certbot in manual mode on a machine that is not
your server, please ensure you're okay with that.
Are you OK with your IP being logged?
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
(Y)es/(N)o: y
Output from authenticator.sh:
RipQQbHO5pG95nzJjouCgTXJMrGTbLKQ5XsV5Zgn7uI
New rrset:
_acme-challenge.example.com. IN TXT 120 "RipQQbHO5pG95nzJjouCgTXJMrGTbLKQ5XsV5Zgn7uI"
Error output from authenticator.sh:
Apr 05 10:51:41 Reading random entropy from '/dev/urandom'
Apr 05 10:51:41 gmysql Connection successful. Connected to database 'pdns' on '127.0.0.1'.
Apr 05 10:51:41 gmysql Connection successful. Connected to database 'pdns' on '127.0.0.1'.
Waiting for verification...
Cleaning up challenges
IMPORTANT NOTES:
- The dry run was successful.
所以这似乎已经解决了。