write a bash script to add a dns cname record on digital ocean using their api and curl
- User
write a bash script to add a dns cname record on digital ocean using their api and curl
- Assistant
Sure! Here's an example of a bash script that uses the DigitalOcean API and curl to add a DNS CNAME record:
#!/bin/bash # Replace the following variables with your own values API_TOKEN="YOUR_DIGITALOCEAN_API_TOKEN" DOMAIN="yourdomain.com" RECORD_NAME="subdomain" RECORD_VALUE="example.com" # Create the JSON payload DATA="{\"type\":\"CNAME\",\"name\":\"$RECORD_NAME\",\"data\":\"$RECORD_VALUE\",\"ttl\":1800}" # Send the API request to create the DNS record response=$(curl -X POST "https://api.digitalocean.com/v2/domains/$DOMAIN/records" \ -H "Authorization: Bearer $API_TOKEN" \ -H "Content-Type: application/json" \ -d "$DATA") # Check the response status if [ "$(echo "$response" | jq -r '.id')" != null ]; then echo "CNAME record created successfully." else echo "Failed to create CNAME record." echo "Response: $response" fiMake sure to replace with your own DigitalOcean API token. Replace with the domain you want to add the CNAME record to. Replace with the name of the subdomain you want to create, and with the value (target) for the CNAME record.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.