Created
March 26, 2024 23:39
-
-
Save davxiao/3ac85e3e16669f69afcb10c05cacc86e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
cloudflare_email='your sign-in email' | |
cloudflare_apikey='your api key' | |
cloudflare_dns_record='your dns record' | |
cloudflare_zone_id='your dns zone id on cloudflare' | |
cloudflare_dns_record_id='your dns record id under the zone' | |
data_string=$( jq -n \ | |
--arg ip "$(curl --silent ipecho.net/plain)" \ | |
--arg nm "$cloudflare_dns_record" \ | |
--arg ty 'A' \ | |
--arg co 'dns record' \ | |
'{content: $ip, name: $nm, proxied: false, type: $ty, comment: $co, ttl: 3600}' ) | |
curl --silent --request PUT \ | |
--url "https://api.cloudflare.com/client/v4/zones/$cloudflare_zone_id/dns_records/$cloudflare_dns_record_id" \ | |
--header 'Content-Type: application/json' \ | |
--header "X-Auth-Email: $cloudflare_email" \ | |
--header "X-Auth-Key: $cloudflare_apikey" \ | |
--data "$data_string" \ | |
| jq |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment