ttl='120'
cron runs every $ttl sec :)
root@kali:~# crontab -l| grep logger
*/2 * * * * /root/cloud-dns.sh 2>&1 | logger
root@kali:~# cat ./cloud-dns.sh
KLUCH='e0f709af7a3ebfd73a14f6d71782eb96'
ZONA='fc9fd399ac93ef301abfe1f14cd75d1e0'
milo='gus@belomor.nl'
a_id='101e6b06425abea8a343290e298d2392'
ip_add=$(curl -4s ipconfig.io)
ip_now=$(curl -s -X GET "https://api.cloudflare.com/client/v4/zones/$ZONA/dns_records?type=A&name="ghost.belomor.nl"&per_page=20&order=type&direction=desc&match=all" \
-H "X-Auth-Email: $milo" \
-H "X-Auth-Key: $KLUCH" \
-H "Content-Type: application/json" | jq -r '.result[0] .content')
if [ $ip_add != $ip_now ]
then curl -s -X PUT "https://api.cloudflare.com/client/v4/zones/$ZONA/dns_records/$a_id" \
-H "X-Auth-Email: $milo" \
-H "X-Auth-Key: $KLUCH" \
-H "Content-Type: application/json" \
--data '{"type":"A","name":"ghost.belomor.nl","content":"'$ip_add'","ttl":120,"proxied":true}' | jq .
else echo $ip_add IS ACTIVE A RECORD!
fi