Initial upload.
This commit is contained in:
commit
df40e7c2ca
45
public_ip.sh
Executable file
45
public_ip.sh
Executable file
@ -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;
|
||||||
|
|
||||||
Loading…
Reference in New Issue
Block a user