commit 4ccfee47dfa0a78aacf9e8dad2391be6a128eeb1 Author: Joachim Lusiardi Date: Thu Sep 12 15:33:07 2019 +0200 add script diff --git a/react_to_ip_change.sh b/react_to_ip_change.sh new file mode 100644 index 0000000..241ca52 --- /dev/null +++ b/react_to_ip_change.sh @@ -0,0 +1,22 @@ +#!/bin/bash + +IP_FILE='/tmp/ipaddress' + +[[ -f "${IP_FILE}" ]] && IP_OLD="$(< "${IP_FILE}" )" + +IP_NEW="$(curl -s -4 http://icanhazip.com/)" + +# work around to report IP to root server +ssh wiebelbach@lusiardi.de -i ~/.ssh/id_rsa_update_ip "echo $IP_NEW > IP" + +if [[ "${IP_OLD}" != "${IP_NEW}" ]]; then + echo "change from ${IP_OLD} to ${IP_NEW}" + echo ${IP_NEW} > ${IP_FILE} + for SCRIPT in `ls /usr/local/etc/ipchange.d/*.sh` + do + ${SCRIPT} ${IP_NEW} + done +else + echo "no update required (still ${IP_OLD})" +fi +