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,6 +100,19 @@ 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)')
ipv6AddressLocalFile="/tmp/dynv6_ip6";
if [ ! -f "${ipv6AddressLocalFile}" ]; then
touch "${ipv6AddressLocalFile}";
fi
if grep --color=never -Fxq ${ipv6Address} "${ipv6AddressLocalFile}"; then
echo "IPv6 is still ${ipv6Address}";
else
echo "IPv6 changed"
echo "${ipv6Address}" > "${ipv6AddressLocalFile}";
ipv6Res=$(curl -s -v "https://ipv6.dynv6.com/api/update?hostname=${hostname}&ipv6=${ipv6Address}&token=${token}") ipv6Res=$(curl -s -v "https://ipv6.dynv6.com/api/update?hostname=${hostname}&ipv6=${ipv6Address}&token=${token}")
ipv6Changed=true; ipv6Changed=true;
@ -107,13 +120,12 @@ if [ "${DYNV6_IPV6_ENABLED}" = "true" ]; then
ipv6Changed=false; ipv6Changed=false;
fi fi
if [ "${ipv6Changed}" = "true" ]; then if [ "${ipv6Changed}" = "true" ]; then
echo "IPv6 changed"
if [ "${DYNV6_MAIL_ENABLED}" = "true" ]; then if [ "${DYNV6_MAIL_ENABLED}" = "true" ]; then
HOSTMACHINE=$(hostname) 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}" 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 fi
# ipv4 # ipv4