-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdynhost.sh.j2
executable file
·31 lines (27 loc) · 959 Bytes
/
dynhost.sh.j2
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#!/usr/bin/env sh
# Author: https://github.com/yjajkiew
# Project: https://github.com/yjajkiew/dynhost-ovh
# Account configuration
HOST={{dynhost_host}}
LOGIN={{dynhost_login}}
PASSWORD={{dynhost_password}}
PATH_LOG={{dynhost_log_dir}}/dynhostd.{{dynhost_host}}.log
# Get current IPv4 and corresponding configured
HOST_IP=$(dig +short $HOST A)
CURRENT_IP=$(curl -m 5 -4 ifconfig.co 2>/dev/null)
if [ -z $CURRENT_IP ]
then
CURRENT_IP=$(dig +short myip.opendns.com @resolver1.opendns.com)
fi
CURRENT_DATETIME=$(date -R)
# Update dynamic IPv4, if needed
if [ -z $CURRENT_IP ] || [ -z $HOST_IP ]
then
echo "[$CURRENT_DATETIME]: No IP retrieved" >> $PATH_LOG
else
if [ "$HOST_IP" != "$CURRENT_IP" ]
then
RES=$(curl -m 5 -L --location-trusted --user "$LOGIN:$PASSWORD" "https://www.ovh.com/nic/update?system=dyndns&hostname=$HOST&myip=$CURRENT_IP")
echo "[$CURRENT_DATETIME]: IPv4 has changed - request to OVH DynHost: $RES" >> $PATH_LOG
fi
fi