輸出雙引號和變數

輸出雙引號和變數

我正在編寫一個腳本來自動在 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.

所以這似乎已經解決了。

相關內容