[Solved] Trying to set up a dynamic DNS with dnsimple.com API

So I'm trying to set up a dynamic DNS thing that would allow me to connect to my home PC with dynamic IP address remotely.

I've set up a system cronjob in /etc/crontab to execute a script every 5 minutes:

*/5 *  * * *   root    /home/pl/bin/dyndns.sh

I've verified that this works by running

grep CRON /var/log/syslog

Now, the script itself is as follows:

#!/bin/bash
 
LOGIN="[email protected]"
TOKEN="my API token"
DOMAIN_ID="mydomain.com"
RECORD_ID="ID of the A record"
IP=`curl -s http://icanhazip.com/`
 
curl -H "Accept: application/json" \
     -H "Content-Type: application/json" \
     -H "X-DNSimple-Token: $LOGIN:$TOKEN" \
     -X "PUT" \
     -i "https://api.dnsimple.com/v1/domains/$DOMAIN_ID/records/$RECORD_ID" \
     -d "{\"record\":{\"content\":\"$IP\"}}"

Yet the record doesn't change. What could be the problem?

So right away I modified the cronjob to

*/5 *   * * *   root    /bin/sh /home/pl/bin/dyndns.sh

I also ran

 /bin/sh /home/pl/bin/dyndns.sh

in terminal and got

{"message":"Authentication failed"}
1 Like

Marked as solved, had the wrong API token...

just a small FYI, if dyndns.sh is executable you don't need the /bin/sh to run it