duckdns improved

This commit is contained in:
2025-07-08 23:44:32 +08:00
parent dd339f2939
commit 53ee621747
4 changed files with 18 additions and 23 deletions

View File

@@ -1 +1,2 @@
.env
*.log

View File

@@ -1,22 +1,9 @@
#!/bin/bash
thisdir="$( dirname "$(readlink -e -- "${BASH_SOURCE[0]}")")"
# https://www.duckdns.org/install.jsp
thisdir="$( dirname "$(readlink -e -- "${BASH_SOURCE[0]}")")"
croncmd="$thisdir/update.sh"
cronjob="*/30 * * * * $croncmd" # every 30 min
( crontab -l | grep -v -F "$croncmd" ; echo "$cronjob" ) | crontab -
cp -f "$thisdir/.env.example" "$thisdir/.env"
cat <<EOF | sudo tee /etc/cron.d/duckdns && crontab -u "$(whoami)" /etc/cron.d/duckdns
# ------------- Minute (0 - 59)
# | ----------- Hour (0 - 23)
# | | --------- Day of month (1 - 31)
# | | | ------- Month (1 - 12)
# | | | | ----- Day of week (0 - 7) (Sunday=0 or 7)
# | | | | |
# * * * * * "command to be executed"
# AAA обновление duckdns ip
0 * * * * $thisdir/update.sh
EOF

View File

@@ -1,3 +1,3 @@
#!/bin/bash
sudo rm -f /etc/cron.d/duckdns
( crontab -l | grep -v -F "duckdns" ) | crontab -

View File

@@ -1,23 +1,30 @@
#!/bin/bash
# shellcheck disable=SC1091
thisdir="$( dirname "$(readlink -e -- "${BASH_SOURCE[0]}")")"
log() {
timestamp="$(date +'%Y-%m-%d %H:%M:%S')"
datestamp="$(date +'%Y-%m-%d')"
[ ! -d "$thisdir/log" ] && mkdir "$thisdir/log"
echo "[$timestamp] $*" >> "$thisdir/log/$datestamp.log"
}
[ ! -f "$thisdir/.env" ] && {
echo "ERROR: .env not exists"
log "ERROR: .env not exists"
exit 1
}
source "$thisdir/.env"
[ -z "$DUCK_TOKEN" ] && {
echo "ERROR: env var DUCK_TOKEN not specified"
log "ERROR: env var DUCK_TOKEN not specified"
exit 1
}
[ -z "$DUCK_DOMAINS" ] && {
echo "ERROR: env var DUCK_DOMAINS not specified"
log "ERROR: env var DUCK_DOMAINS not specified"
exit 1
}
curl -k "https://www.duckdns.org/update?domains=${DUCK_DOMAINS}&token=${DUCK_TOKEN}&ip=${DUCK_IP}"
result=$(curl -s "https://www.duckdns.org/update?domains=${DUCK_DOMAINS}&token=${DUCK_TOKEN}&ip=${DUCK_IP}")
log "$result"