Use correct mechanism

This commit is contained in:
Alexander Schäferdiek 2020-06-18 18:40:58 +02:00
parent 8c82fa5b70
commit dc5c6551c4

View file

@ -100,19 +100,31 @@ echo "Checking ${hostname}"
if [ "${DYNV6_IPV6_ENABLED}" = "true" ]; then if [ "${DYNV6_IPV6_ENABLED}" = "true" ]; then
echo "Testing IPv6"; echo "Testing IPv6";
ipv6Address=$(LC_ALL=C /usr/bin/ip -c=never -6 -o a s dev ${DYNV6_IPV6_INTERFACE} | grep --color=never -Po '(?<=inet6 )(2.*?)(?=\/64 scope global dynamic mngtmpaddr)') ipv6Address=$(LC_ALL=C /usr/bin/ip -c=never -6 -o a s dev ${DYNV6_IPV6_INTERFACE} | grep --color=never -Po '(?<=inet6 )(2.*?)(?=\/64 scope global dynamic mngtmpaddr)')
ipv6Res=$(curl -s -v "https://ipv6.dynv6.com/api/update?hostname=${hostname}&ipv6=${ipv6Address}&token=${token}")
ipv6Changed=true;
if [ "${ipv6Res}" = "addresses unchanged" ]; then ipv6AddressLocalFile="/tmp/dynv6_ip6";
ipv6Changed=false;
if [ ! -f "${ipv6AddressLocalFile}" ]; then
touch "${ipv6AddressLocalFile}";
fi fi
if [ "${ipv6Changed}" = "true" ]; then
echo "IPv6 changed"
if [ "${DYNV6_MAIL_ENABLED}" = "true" ]; then if grep --color=never -Fxq ${ipv6Address} "${ipv6AddressLocalFile}"; then
HOSTMACHINE=$(hostname) echo "IPv6 is still ${ipv6Address}";
echo -e "IPv6 for ${hostname} on host ${HOSTMACHINE} changed to ${ipv6Address}" | mailx -s "[dynv6 IPv6 ${HOSTMACHINE}] IPv6 changed for ${hostname}" "${DYNV6_MAIL_ADDRESS}" else
fi echo "IPv6 changed"
echo "${ipv6Address}" > "${ipv6AddressLocalFile}";
ipv6Res=$(curl -s -v "https://ipv6.dynv6.com/api/update?hostname=${hostname}&ipv6=${ipv6Address}&token=${token}")
ipv6Changed=true;
if [ "${ipv6Res}" = "addresses unchanged" ]; then
ipv6Changed=false;
fi
if [ "${ipv6Changed}" = "true" ]; then
if [ "${DYNV6_MAIL_ENABLED}" = "true" ]; then
HOSTMACHINE=$(hostname)
echo -e "IPv6 for ${hostname} on host ${HOSTMACHINE} changed to ${ipv6Address}" | mailx -s "[dynv6 IPv6 ${HOSTMACHINE}] IPv6 changed for ${hostname}" "${DYNV6_MAIL_ADDRESS}"
fi
fi
fi fi
fi fi