Last active 2 hours ago

Useful for dynamic IPs and automatic updates to combine with cron

update_cdmon.sh Raw
1#!/bin/bash
2
3APIKEY=""
4DOMAIN=""
5
6IP_FILE="ip.txt"
7
8# Get current public IP
9NEW_IP=$(curl -s https://api.ipify.org)
10
11if [ -f $IP_FILE ]; then
12 OLD_IP=$(cat $IP_FILE)
13 if [ $NEW_IP == $OLD_IP ]; then
14 echo "IP has not changed."
15 exit 0
16 fi
17fi
18
19curl --include \
20 --request POST \
21 --header "Content-Type: application/json" \
22 --header "Accept: application/json" \
23 --header "apikey: $APIKEY" \
24 --data-binary "{\"data\": {\"domain\": \"$DOMAIN\", \"current\": {\"host\": \"@\", \"type\": \"A\"}, \"new\": {\"ttl\": 1100, \"destination\": \"$NEW_IP\"}}}" \
25 https://api-domains.cdmon.services/api-domains/dnsrecords/edit
26
27echo "$NEW_IP" > $IP_FILE