Skip to content

Commit 24c3cd7

Browse files
committed
change dig by curl & log mode
1 parent ef8adf4 commit 24c3cd7

File tree

2 files changed

+25
-23
lines changed

2 files changed

+25
-23
lines changed

README.md

+5-9
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,17 @@
11
# dynhost-ovh
22
A simple (cron) script to update DynHost on OVH hosting
3+
Fork of: https://github.com/yjajkiew/dynhost-ovh
4+
Link: https://yann.me/dynhost-ovh-pour-raspberry-pi-ou-une-machine-linux/
35

46
# Prerequisites
5-
This script works with two linux commands : curl and dig.
6-
If you do not have the dig you must install it from the package "dnsutils" :
7-
```sh
8-
sudo apt-get update
9-
sudo apt-get install dnsutils
10-
```
7+
This script works with two linux commands : curl & host
118

129
# How to use
1310
1. Download the dynhost.sh script and put it in the folder /etc/cron.hourly (to check every hour)
1411
2. Add execution permissions to file : chmod +x dynhost.sh
1512
3. Modify the script with variables : HOST, LOGIN, PASSWORD
1613

1714
# How it works
18-
1. The command dig is used to retrieve the IP address of your domain name.
15+
1. The command host is used to retrieve the IP address of your domain name.
1916
2. The command curl (with the website ifconfig.co) is used to retrieve the current public IP address of your machine.
20-
3. The two IPs are compared and if necessary a curl command to OVH is used to update your DynHost with your current public IP address.
21-
17+
3. The two IPs are compared and if necessary a curl command to OVH is used to update your DynHost with your current public IP address.

dynhost.sh

+20-14
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,23 @@
1-
#!/usr/bin/env sh
1+
#/bin/sh
22

3-
# Account configuration
4-
HOST=DOMAINE_NAME
5-
LOGIN=LOGIN
6-
PASSWORD=PASSWORD
7-
8-
PATH_LOG=/var/log/dynhostovh.log
3+
### CONFIG ###
4+
HOST="DOMAIN_NAME"
5+
LOGIN="LOGIN"
6+
PASSWORD="PASSWORD"
7+
LOG_FILE=/var/log/dynhost.log
98

109
# Get current IPv4 and corresponding configured
11-
HOST_IP=$(dig +short $HOST A)
10+
HOST_IP=$(host -4 ${HOST} | cut -d" " -f4)
1211
CURRENT_IP=$(curl -m 5 -4 ifconfig.co 2>/dev/null)
13-
if [ -z $CURRENT_IP ]
12+
13+
### EXECUTION ###
14+
touch "$LOG_FILE"
15+
LOG_PREFIX="$(date) - Current IP: $CURRENT_IP ; Host IP: $HOST_IP"
16+
17+
if [ -z $CURRENT_IP ] || [ -z $HOST_IP ]
1418
then
15-
CURRENT_IP=$(dig +short myip.opendns.com @resolver1.opendns.com)
16-
fi
17-
CURRENT_DATETIME=$(date -R)
19+
echo "No IP retrieved" >> $PATH_LOG
20+
else
1821

1922
# Update dynamic IPv4, if needed
2023
if [ -z $CURRENT_IP ] || [ -z $HOST_IP ]
@@ -23,7 +26,10 @@ then
2326
else
2427
if [ "$HOST_IP" != "$CURRENT_IP" ]
2528
then
26-
RES=$(curl -m 5 --user "$LOGIN:$PASSWORD" "https://www.ovh.com/nic/update?system=dyndns&hostname=$HOST&myip=$CURRENT_IP")
27-
echo "[$CURRENT_DATETIME]: IPv4 has changed - request to OVH DynHost: $RES" >> $PATH_LOG
29+
RES=$(curl -m 5 --insecure --user "$LOGIN:$PASSWORD" "https://www.ovh.com/nic/update?system=dyndns&hostname=$HOST&myip=$CURRENT_IP")
30+
LOG_SUFFIX="IP has changed - Result request dynHost: $RES"
31+
else
32+
LOG_SUFFIX="IP has not changed"
2833
fi
2934
fi
35+
echo "$LOG_PREFIX - $LOG_SUFFIX" >> "$LOG_FILE"

0 commit comments

Comments
 (0)