react_to_ip_changes/react_to_ip_change.sh

23 lines
563 B
Bash
Raw Permalink Normal View History

2019-09-12 15:33:07 +02:00
#!/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