Skip to content

Instantly share code, notes, and snippets.

@jush
Last active November 20, 2020 18:47
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 jush/a100f881adb94e129a4714c3acd52f76 to your computer and use it in GitHub Desktop.
Save jush/a100f881adb94e129a4714c3acd52f76 to your computer and use it in GitHub Desktop.
Simple Namecheap Dynamic DNS client
#!/bin/sh
set -eu
FETCH="curl -s"
# or for curl:
#FETCH="curl -s"
# $1: your domain
# $2: subdomain to update use @ for TLD
# $3: the password given to you by Namecheap's web interface
#
# Rerun this script every 5 minutes. Crontab entry (not as root):
# */5 * * * * namecheap-ddns bla.com @ asdjfasfasdfasdf https://hc-ping.com asdfg-asdf-asdf-asdfg-asdjfkl
domain=$1
host=$2
password=$3
healthcheck_host=$4
healthcheck_id=$5
curl -sS -X POST -o /dev/null "$healthcheck_host/$healthcheck_id/start"
out=$(${FETCH} "https://dynamicdns.park-your-domain.com/update?host=${host}&domain=${domain}&password=${password}")
grep -q "<ErrCount>0</ErrCount>" <<EOF && curl -sS -X POST -o /dev/null "$healthcheck_host/$healthcheck_id" && exit 0
${out}
EOF
cat <<EOF
${out}
EOF
curl -sS -X POST -o /dev/null --fail "$healthcheck_host/$healthcheck_id"
exit 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment