如何从Azure SQL托管实例连接字符串中提取dnszone

huangapple go评论118阅读模式
英文:

How to grep dnszone from azure SQL Managed Instance connection-string

问题

要求:自动化部署Azure SQL MI并连接Web应用程序。
每次我创建SQL MI时,它会生成一个随机的“dnszone”,我无法将其捕获到我需要使用bash命令创建连接字符串的文件中。下面是我使用的示例脚本:

$instanceName=sqlmi-poc
$dnszone=65r4897a552e <this i need to store>
jdbc:sqlserver://$instanceName.$dnszone.database.windows.net:1433;encrypt=true;trustServerCertificate=false;hostNameInCertificate=*.$dnszone.database.windows.net;loginTimeout=30;

我尝试了几种选项,但无法提取$dnszone的值:

Get-AzSqlInstance -ResourceGroupName {rg-name} -Name {mi-name}
az sql mi list -g $rgp | grep "fullyQualifiedDomainName"

我感谢任何帮助来捕获类似这样的dnszone值:

$dnszone="value"
英文:

Requirement: To automate the deployment of azure sql mi and connect the web application to it.
Everytime I create sql mi it generate a random "dnszone" which I am unable to capture in file which I need to create a connection string using bash command. below is sample scripts I have used:

$instanceName=sqlmi-poc
$dnszone=65r4897a552e &lt;this i need to store&gt;
jdbc:sqlserver://$instanceName.$dnszone.database.windows.net:1433;encrypt=true;trustServerCertificate=false;hostNameInCertificate=*.$dnszone.database.windows.net;loginTimeout=30;

I have tried couple of option available by unable to grep the $dnszone value

Get-AzSqlInstance -ResourceGroupName {rg-name} -Name {mi-name}
az sql mi list -g $rgp | grep &quot;fullyQualifiedDomainName&quot;

I appreciate any help to capture the dnszone value like this:

$dnszone=&quot;value&quot;

Thanks

答案1

得分: 1

尝试以下类似的内容:

PS Azure:\&gt; $dnszone = Get-AzSqlInstance -ResourceGroupName "rgouthindia" -Name "myinstancesouthindia*"

PS Azure:\&gt; $dnszone.DnsZone
91d79b7f688b
英文:

Try something like below:

PS Azure:\&gt; $dnszone =Get-AzSqlInstance -ResourceGroupName &quot;rgouthindia&quot; -Name &quot;myinstancesouthindia*&quot;

PS Azure:\&gt; $dnszone.DnsZone
91d79b7f688b

答案2

得分: 0

finally after working for hours there is solution and thought to share it.

x="az sql mi list -g $rgp | grep "fullyQualifiedDomainName";"

chksqlmi=$(eval "$x")

y=$(echo $chksqlmi | tr -d ''"'"' '')

prefix="fullyQualifiedDomainName: $instanceName."

suffix=".database.windows.net,"

dnszone=$(echo $y | sed -e "s/^$prefix//" -e "s/$suffix$//")
英文:

finally after working for hours there is solution and thought to share it.

x=&quot;az sql mi list -g $rgp | grep &quot;fullyQualifiedDomainName&quot;;&quot;

chksqlmi=$(eval &quot;$x&quot;)

y=$(echo $chksqlmi | tr -d &#39;&quot;&#39;)

prefix=&quot;fullyQualifiedDomainName: $instanceName.&quot;

suffix=&quot;.database.windows.net,&quot;

dnszone=$(echo $y | sed -e &quot;s/^$prefix//&quot; -e &quot;s/$suffix$//&quot;)

huangapple
  • 本文由 发表于 2020年1月6日 15:07:34
  • 转载请务必保留本文链接:https://go.coder-hub.com/59607991.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定