You want to automate the process of updating a dynDNS server, and you'll be using the
cf-dyndns.sh script in the Hermes framework.
To run the script as a cron job, first find out its name (likely something like
cf-dyndns.sh). You can do this by running:
``
bash
$ hermes whoami | grep cf-dyndns
`
This will print the name of the user who owns the cron job.
Once you have the name, add a new file in your .hermes/
directory with the following content:
`
shell
#!/bin/bash
PATH="/var/auctex/files/awgs/dyn"
sleep 1 && echo "STATUS:NO_CHANGE" > /home/$USER/.hermes/skills/future-dynamic-ip.sh
if ! curl -O https://example.com/update.json; then
echo "ERROR"
exit 1
fi
# Remove the status flag (optional)
sed '/^\$/d' update.json --in-place
`
The first line initializes a bash script that simulates the API request and returns success.
Change " target="_blank" rel="noopener">http://example.com/update.json to the actual URL of your update endpoint, replacing
'update.json' by a valid filename of your choice (avoid names starting with "y" as they will always end with
.yzml, which may not work because DynDNS checks for these files when updating).
You can install curl and add it to your system's PATH if you haven't done so yet. Here are the steps:
1. On Ubuntu-based systems you can use
sudo apt-get or just type in
curl.
2. You might need to also install
wget for more modern updates.
After these changes, run:
``
shell
$ hermes curl https://example.com/update.json > script.sh && chmod +x script.sh && crond script.sh
`
This crontab will create the cron job every minute that runs the updated script. Don't forget to modify the PATH
variable in your script and the actual URL (if new) of your update endpoint.
Finally, check if DynDNS server is responding without an error: run:
`
shell
$ ping -c 1 dyn.example.com
`
Or for different servers: ping -c 1 dnn.example.com
. This command should return at least " pong" to confirm it's working. If the previous commands worked, you've successfully set up DynDNS using curl and cron as part of Hermes.
Here is a more generic version that includes user authentication:
`
perl
#!/bin/bash
#!/usr/bin/perl -w
sleep 1 && echo "STATUS:NO_CHANGE" >> ~/.hermes/skills/future-dynamic-ip.sh
declare username="your_username"
declare password="your_password"
api_url='https://example.com/update.json'
ping https://$username:$password@dyn.example.com &> /dev/null || { ping -c 1 dnn$username; echo 'Status NO_CHANGE'; :; }
sed '/^\$/d' update.json --in-place
`
In the script above, I have defined two variables username
and password` that you are using to authenticate for your DynDNS server.
You can replace these variables with your own if needed. The ping command is to ensure that dynamic IP information in response to an API call doesn't cause errors that might prevent yourDyn DNS from working properly.
The cron job will run the script at each new minute, so it's very useful for dynamic DNS when you want automated updates of your server IP.
However, as your users may expect notification if any error occurs during updating process or if some DynaDNS update fails then one can use an email notification handler.