Skip to content

Commit

Permalink
ddns-scripts: 2nd fix detecting local ip from ip command
Browse files Browse the repository at this point in the history
Signed-off-by: Christian Schoenebeck <[email protected]>
  • Loading branch information
chris5560 committed Jan 16, 2017
1 parent d093904 commit 04d808e
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions net/ddns-scripts/files/dynamic_dns_functions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -886,7 +886,7 @@ send_update() {
get_local_ip () {
# $1 Name of Variable to store local IP (LOCAL_IP)
local __CNT=0 # error counter
local __RUNPROG __DATA __URL __ERR
local __RUNPROG __DATA __URL __ERR __TMP

[ $# -ne 1 ] && write_log 12 "Error calling 'get_local_ip()' - wrong number of parameters"
write_log 7 "Detect local IP on '$ip_source'"
Expand Down Expand Up @@ -917,9 +917,11 @@ get_local_ip () {
# 5: eth1 inet6 fd43:5368:6f6d:6500:a00:27ff:fed0:1032/64 scope global dynamic \ valid_lft 14352sec preferred_lft 14352sec
# 5: eth1 inet6 2002:b0c7:f326::a00:27ff:fed0:1032/64 scope global dynamic \ valid_lft 14352sec preferred_lft 14352sec

# remove remove remove replace remove remove
# link inet6 fxxx sec forever=>-1 between / and pref.. linestart to inet
sed -i "/link/d; /inet6 f/d; s/sec//g; s/forever/-1/g; s/\/.*preferred_lft//g; s/^.*$ip_interface *//g" $DATFILE
# remove remove remove replace replace
# link inet6 fxxx sec forever=>-1 / => ' ' to separate subnet from ip
sed "/link/d; /inet6 f/d; s/sec//g; s/forever/-1/g; s/\// /g" $DATFILE | \
awk '{ print $3" "$4" "$NF }' > ${DATFILE}_tmp
# we only need inet? IP prefered time

local __TIME4=0; local __TIME6=0
local __TYP __ADR __TIME
Expand All @@ -934,7 +936,8 @@ get_local_ip () {
__DATA4="$__ADR"
__TIME4="$__TIME"
}
done < $DATFILE
done < ${DATFILE}_tmp
rm ${DATFILE}_tmp
else
write_log 3 "ip Error: '$__ERR'"
write_log 7 "$(cat $ERRFILE)" # report error
Expand Down

0 comments on commit 04d808e

Please sign in to comment.