Editing my dyndns.sh - help needed


#1

Hello,
I have successfully set up my server to update my IP address. This is done by using the following script:
https://gist.github.com/TheFirsh/c9f72970eaae3aec04beb1106cc304bc

However, it only updates the “Type: A, Name: www” record. Not the “Type: A, Name: domain-name(dot)asdf” one. So the only way accessing my website is by prepending “www” to the url. But I’d like both, “www(dot)domain-name(dot)asdf” and “domain-name(dot)asdf” to be updated by the script.
I have tried using:
#…
zone_name=“follow-the-white-rabbit(dot)net”
record_name=“follow-the-white-rabbit(dot)net” #previously “www(dot)follow-the-white-rabbit(dot)net”
#…
update=$(curl -s -X PUT “https://api.cloudflare.com/client/v4/zones/$zone_identifier/dns_records/$record_identifier” -H “X-Auth-Email: $auth_email” -H “X-Auth-Key: $auth_key” -H “Content-Type: application/json” --data “{“id”:”$zone_identifier",“type”:“A”,“name”:“www.$record_name”,“content”:"$ip"}")

But this causes the www name to be overwritten with the domain name.

Any idea?
thanks


#2

You probably don’t have the correct $record_identifier for the non-www record. That’s why your ‘www’ name is being overwritten by the domain name.


#3

I see. How can I get the other identifier?

I have tried this:

zone_name="follow-the-white-rabbit.net"
record_name="www.follow-the-white-rabbit.net"
record_name2=zone_name
#....
ip=$(curl -s http://ipv4.icanhazip.com)
ip_file="ip.txt"
id_file="cloudflare.ids"
id_file2="cloudflare2.ids" #file for the non-www identifiers
log_file="cloudflare.log"
#....

if [ -f $id_file2 ] && [ $(wc -l $id_file2 | cut -d " " -f 1) == 2 ]; then
    zone_identifier2=$(head -1 $id_file2)
    record_identifier2=$(tail -1 $id_file2)
else
    zone_identifier2=$(curl -s -X GET "https://api.cloudflare.com/client/v4/zones?name=$zone_name" -H "X-Auth-Email: $auth_email" -H "X-Auth-Key: $auth_key" -H "Content-Type: application/json" | grep -Po '(?<="id":")[^"]*' | head -1 )
    record_identifier2=$(curl -s -X GET "https://api.cloudflare.com/client/v4/zones/$zone_identifier2/dns_records?name=$record_name2" -H "X-Auth-Email: $auth_email" -H "X-Auth-Key: $auth_key" -H "Content-Type: application/json"  | grep -Po '(?<="id":")[^"]*')
    echo "$zone_identifier2" > $id_file2
    echo "$record_identifier2" >> $id_file2
fi

#...

#4

However, I couldn’t get the other identifier. only one line of a hex string appeared in the new id file


#5

I access the API using ‘curl’ using the commands from the API docs. No need to add any parameters beyond the Zone ID. It’ll list all your DNS records.

https://api.cloudflare.com/#dns-records-for-a-zone-list-dns-records


#6

Ok, got the other zone id. what should i do with it now?


#7

I hope you meant the other DNS Record ID. Now you can use that for your $record_identifier variable.