gpt-3.5-turbo-0613· openai
Suzhen/CodeChat
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 adds a DNS CNAME record on DigitalOcean using their API and curl:
#!/bin/bash # Define your DigitalOcean API token and domain name DO_API_TOKEN="your_digitalocean_api_token" DOMAIN_NAME="example.com" # Define the subdomain and the target domain for the CNAME record SUBDOMAIN="subdomain" TARGET_DOMAIN="example.digitalocean.com" # Make the API request to add the DNS CNAME record response=$(curl -X POST -H "Content-Type: application/json" -H "Authorization: Bearer $DO_API_TOKEN" -d "{\"type\":\"CNAME\",\"name\":\"$SUBDOMAIN\",\"data\":\"$TARGET_DOMAIN\"}" "https://api.digitalocean.com/v2/domains/$DOMAIN_NAME/records") # Check if the API request was successful if [[ $(echo $response | jq -r '.id') ]]; then echo "DNS CNAME record added successfully!" else echo "Failed to add DNS CNAME record:" echo "$response" fiMake sure to replace
your_digitalocean_api_token,example.com,subdomain, andexample.digitalocean.comwith your own information.To run the script, save it to a file (e.g.,
add_cname_record.sh), make it executable (chmod +x add_cname_record.sh), and execute it (./add_cname_record.sh).
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.