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. Escape all special characters in the script as if it were passed through htmlspecialchars
- Assistant
Sure! Here's a bash script to add a DNS CNAME record on DigitalOcean using their API and
curl. It also useshtmlspecialcharsto escape any special characters in the script:#!/bin/bash # Set your DigitalOcean API token DO_API_TOKEN="YOUR_DIGITALOCEAN_API_TOKEN" # Set your domain name and record details DOMAIN="example.com" RECORD_NAME="www" CNAME_TARGET="myapp.digitalocean.com" # Escape special characters using htmlspecialchars equivalent escape_special_chars() { local string="${1//&/&}" string="${string//</<}" string="${string//>/>}" string="${string//\"/"}" string="${string//\`/\`}" string="${string//\//\/}" string="${string//\'/\'}" printf "%s" "$string" } # Create CNAME record using DigitalOcean API create_cname_record() { local json_payload='{ "type": "CNAME", "name": "'$(escape_special_chars "$RECORD_NAME")'", "data": "'$(escape_special_chars "$CNAME_TARGET")'", "ttl": 1800 }' echo "Creating CNAME record '$RECORD_NAME.$DOMAIN' with target '$CNAME_TARGET'..." curl -X POST -H "Content-Type: application/json" -H "Authorization: Bearer $DO_API_TOKEN" \ -d "$json_payload" "https://api.digitalocean.com/v2/domains/$DOMAIN/records" echo "CNAME record created successfully." } # Call the function to create the CNAME record create_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.