Skip to content

Instantly share code, notes, and snippets.

@ps1dr3x
Last active November 16, 2022 10:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ps1dr3x/3951195b568e004533a1ff3b9ae63a34 to your computer and use it in GitHub Desktop.
Save ps1dr3x/3951195b568e004533a1ff3b9ae63a34 to your computer and use it in GitHub Desktop.
Update DynDNS (OVH)
#!/bin/bash
# Don't forget to chmod +x update-dynhost-ovh.sh and add the cron
# */5 * * * * update-dynhost-ovh.sh
DOMAIN=""
USERNAME=""
PASSWORD=""
LOG_FILE="/var/log/update-dyndns-ovh.log"
LOG_TIMESTAMP=$(date +%s)
IP_DNS=$(dig +short $DOMAIN)
IP_LOCAL=$(curl https://api.ipify.org)
UPDATE_RESULT=""
if [[ "$IP_DNS" == "" || "$IP_LOCAL" == "" ]]; then
UPDATE_RESULT="Got an empty response for IP_DNS and/or IP_LOCAL (IP_DNS: $IP_DNS IP_LOCAL: $IP_LOCAL). Skipping update."
elif [[ "$IP_DNS" != "$IP_LOCAL" ]]; then
echo "$LOG_TIMESTAMP: Found a different IP. IP_DNS: $IP_DNS IP_LOCAL: $IP_LOCAL. Updating DNS..." >> "$LOG_FILE"
UPDATE_RESULT=$(curl "https://www.ovh.com/nic/update?system=dyndns&hostname=$DOMAIN&myip=$CURRENT_IP" -u "$USERNAME:$PASSWORD")
else
UPDATE_RESULT="The DNS is already up to date."
fi
echo "$LOG_TIMESTAMP: UPDATE_RESULT: $UPDATE_RESULT" >> "$LOG_FILE"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment