bash - REST API call to get the list of SQL databases from Azure -


i need make call using azure rest api list of databases , delete particular database if exits.

if give me shell script helpful. tried list azure sql databases on given server

wget -u --no-check-certificate    https://management.core.windows.net:8443/  subscriptionid/services/sqlservers/servers/servername/p1y/databases? contentview=generic --2016-01-22 22:15:57--     https://management.core.windows.net:8443/${subscriptionid}/services/sqlservers/s    ervers/${servername}/databases?contentview=generic resolving management.core.windows.net (management.core.windows.net)...xx.xxx.xxx.xxx connecting management.core.windows.net (management.core.windows.net)|xx.xxx.xxx.xxx|:8443... connected. http request sent, awaiting response... 403 forbidden 2016-01-22 22:15:57 error 403: forbidden. 

i think can use curl instead of wget. but, before use curl, need create , upload certificate.

first, need install openssl , curl in machine. , can create .pem file following command:

openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout azure-cert.pem -out azure-cert.pem 

note: openssl ask input lot of things.

this local usage. .pem file, can create .cer file uploaded azure. use following command create one.

openssl x509 -outform der -in azure-cert.pem -out azure-cert.cer 

go the classic portal of azure, in management certificates page of settings, click upload, , choose .cer file created above.

wait few seconds, , after certificate created, can use following command list of sql database in sql server.

curl -e azure-cert.pem -h "x-ms-version: 2011-10-01" "https://management.core.windows.net:8443/{subscriptionid}/services/sqlservers/servers/{servername}/databases?contentview=generic" 

if want delete sql database, can use following command.

curl -x delete -e azure-cert.pem -h "x-ms-version: 2011-10-01" "https://management.core.windows.net:8443/{subscriptionid}/services/sqlservers/servers/{servername}/databases/{databasename}" 

the output of these commands xml code hard read. so, recommend use azure cli instead. but, if insist, , need more information curl http jobs, see here. if need more information azure rest api, see here


Comments