Last active
November 16, 2022 10:11
-
-
Save ps1dr3x/3951195b568e004533a1ff3b9ae63a34 to your computer and use it in GitHub Desktop.
Update DynDNS (OVH)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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