二重引用符と変数の出力

二重引用符と変数の出力

PowerDNSで暗号化を自動化するスクリプトを作成しています(debianで実行される単純なbashシェルスクリプトです)。

Certbotはスクリプトを実行して呼び出して$ CETBOT_VALIDATION変数を提供します。

私はすでに1つのトピックを読みました。こここれは必要性を示します'"content"'。一重引用符  'と二重引用符を参照してください"。 (私はこれをコードの複数の反復で試しましたが、役に立ちませんでした。)拡張変数を引用符で囲んで出力するのが困難です。以下は私が試したアプローチの1つです。

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

スクリプト authenticater.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.

だからこの問題は解決されたようです。

おすすめ記事