File tree 2 files changed +25
-23
lines changed
2 files changed +25
-23
lines changed Original file line number Diff line number Diff line change 1
1
# dynhost-ovh
2
2
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/
3
5
4
6
# 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
11
8
12
9
# How to use
13
10
1 . Download the dynhost.sh script and put it in the folder /etc/cron.hourly (to check every hour)
14
11
2 . Add execution permissions to file : chmod +x dynhost.sh
15
12
3 . Modify the script with variables : HOST, LOGIN, PASSWORD
16
13
17
14
# 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.
19
16
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.
Original file line number Diff line number Diff line change 1
- #! /usr/ bin/env sh
1
+ # / bin/sh
2
2
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
9
8
10
9
# Get current IPv4 and corresponding configured
11
- HOST_IP=$( dig +short $ HOST A )
10
+ HOST_IP=$( host -4 ${ HOST} | cut -d " " -f4 )
12
11
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 ]
14
18
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
18
21
19
22
# Update dynamic IPv4, if needed
20
23
if [ -z $CURRENT_IP ] || [ -z $HOST_IP ]
23
26
else
24
27
if [ " $HOST_IP " != " $CURRENT_IP " ]
25
28
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"
28
33
fi
29
34
fi
35
+ echo " $LOG_PREFIX - $LOG_SUFFIX " >> " $LOG_FILE "
You can’t perform that action at this time.
0 commit comments