Added variables for other settings and improved output for logging.

This commit is contained in:
rich committed 2021-02-06 12:09:01 -05:00
1 parent 71c7ad763e
commit da8938d211
1 file changed
+13 -4
+13 -4
View File
@@ -7,13 +7,22 @@ ZONE_ID="ZONE ID NUMBER HERE"
#This can only be gotten by using the API to get a list of records for the zone.
RECORD_ID="<RECORD ID NUMBER HERE"
RECORD_NAME="example.com"
RECORD_TYPE="A"
TTL=1
IP="$(curl http://ipinfo.io/ip 2>/dev/null)"
IP="$(curl -s http://ipinfo.io/ip 2> /dev/null)"
echo "Current IP Address: $IP"
DATE=$(date +%Y%m%d-%H%M%S)
curl -X PUT "https://api.cloudflare.com/client/v4/zones/$ZONE_ID/dns_records/$RECORD_ID" \
RESPONSE=$(curl -s -X PUT "https://api.cloudflare.com/client/v4/zones/$ZONE_ID/dns_records/$RECORD_ID" \
-H "X-Auth-Email: $AUTH_EMAIL" \
-H "X-Auth-Key: $CLOUDFLARE_API_KEY" \
-H "Content-Type: application/json" \
--data '{"type":"A","name":"$RECORD_NAME","content":"'$IP'","ttl":1}'
--data '{"type":"$RECORD_TYPE","name":"$RECORD_NAME","content":"'$IP'","ttl":$TTL}')
if [ $(echo "$RESPONSE" | grep '"success":true' | wc -l) -eq 1 ]; then
echo "$DATE|IP:$IP|CF Update: Success"
else
echo "$DATE|IP:$IP|CF Update: Failure"
echo "Response: $RESPONSE"
fi