Skip to content

Commit ef8adf4

Browse files
authored
Merge pull request yjajkiew#3 from alberto743/portability+fallback
Assure the portability of the shebang. Prevent curl hanging in case o…
2 parents 40426d3 + 0b7ce9e commit ef8adf4

File tree

1 file changed

+18
-27
lines changed

1 file changed

+18
-27
lines changed

dynhost.sh

+18-27
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,29 @@
1-
#/bin/sh
2-
3-
#
4-
# CONFIG
5-
#
1+
#!/usr/bin/env sh
62

3+
# Account configuration
74
HOST=DOMAINE_NAME
85
LOGIN=LOGIN
96
PASSWORD=PASSWORD
107

11-
PATH_LOG=/var/log/dynhost
12-
CURRENT_DATE=`date`
13-
14-
#
15-
# GET IPs
16-
#
8+
PATH_LOG=/var/log/dynhostovh.log
179

18-
HOST_IP=`dig +short $HOST`
19-
CURRENT_IP=`curl -4 ifconfig.co`
10+
# Get current IPv4 and corresponding configured
11+
HOST_IP=$(dig +short $HOST A)
12+
CURRENT_IP=$(curl -m 5 -4 ifconfig.co 2>/dev/null)
13+
if [ -z $CURRENT_IP ]
14+
then
15+
CURRENT_IP=$(dig +short myip.opendns.com @resolver1.opendns.com)
16+
fi
17+
CURRENT_DATETIME=$(date -R)
2018

21-
#
22-
# DO THE WORK
23-
#
19+
# Update dynamic IPv4, if needed
2420
if [ -z $CURRENT_IP ] || [ -z $HOST_IP ]
2521
then
26-
echo "No IP retrieved" >> $PATH_LOG
22+
echo "[$CURRENT_DATETIME]: No IP retrieved" >> $PATH_LOG
2723
else
28-
if [ "$HOST_IP" != "$CURRENT_IP" ]
29-
then
30-
echo "$CURRENT_DATE"": Current IP:" "$CURRENT_IP" "and" "host IP:" "$HOST_IP" " IP has changed!" >> $PATH_LOG
31-
RES=`curl --user "$LOGIN:$PASSWORD" "https://www.ovh.com/nic/update?system=dyndns&hostname=$HOST&myip=$CURRENT_IP"`
32-
echo "Result request dynHost:" >> $PATH_LOG
33-
echo "$RES" >> $PATH_LOG
34-
else
35-
echo "$CURRENT_DATE"": Current IP:" "$CURRENT_IP" "and" "Host IP:" "$HOST_IP" " IP has not changed" >> $PATH_LOG
36-
fi
24+
if [ "$HOST_IP" != "$CURRENT_IP" ]
25+
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
28+
fi
3729
fi
38-

0 commit comments

Comments
 (0)