add script

This commit is contained in:
Joachim Lusiardi 2019-09-12 15:33:07 +02:00
commit 4ccfee47df
1 changed files with 22 additions and 0 deletions

22
react_to_ip_change.sh Normal file
View File

@ -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