From df40e7c2ca9e5d753307f340d30cd33b272e55ba Mon Sep 17 00:00:00 2001 From: tilman Date: Sun, 3 Feb 2019 22:01:10 +0100 Subject: [PATCH] Initial upload. --- public_ip.sh | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100755 public_ip.sh diff --git a/public_ip.sh b/public_ip.sh new file mode 100755 index 0000000..4d159dc --- /dev/null +++ b/public_ip.sh @@ -0,0 +1,45 @@ +#!/bin/bash + +#Aktuelle öffentliche IP ermitteln. +public=`wget -q -O- checkip.dyndns.org | grep -Eo '\<[[:digit:]]{1,3}(\.[[:digit:]]{1,3}){3}\>'`; +#Bisher bekannte öffentliche IP auslesen. + +old=`cat /opt/publicip2nginx/current.txt`; + +nginx="/etc/nginx/conf.d/hw12.conf"; +temp="/opt/publicip2nginx/hw12.conf"; + +log_time=$(/bin/date +%Y%m%d-%H%M%S); + +#Prüfe nach bisheriger IP. +if [ -z "$old" ]; then + echo $log_time": Keine alte IP gefunden." >> /var/log/public2ip.log; + exit; +fi +#Prüfe nach aktueller IP. +if [ -z "$public" ]; then + echo $log_time": Keine aktuelle IP gefunden." >> /var/log/public2ip.log; + exit; +fi + +#Vergleich +if [ $old = $public ]; then + + exit; + +else + + sed /allow/s/$old/$public/g $nginx > $temp; + + #Dateien verschieben + mv $nginx $nginx.".bak"; + mv $temp $nginx; + service nginx reload; + + #Log bei Änderung und aktuelle IP in Datei schreiben. + echo $log_time":" $old $public >> /var/log/public2ip.log; + echo $public > /opt/publicip2nginx/current.txt; +fi + +exit; +