sarmic/nginx-allow-dynamicip/nginx-allow-dynamicip.sh

23 lines
420 B
Bash
Raw Normal View History

2022-06-02 00:30:16 +05:00
#!/bin/bash
CONFIG=/etc/nginx/sites-available/$1
2022-06-02 00:30:16 +05:00
DOMAIN=$2
2022-06-02 20:48:34 +05:00
IP=$(dig $DOMAIN +short)
2022-06-02 00:30:16 +05:00
IP_OLD=$(grep -A0 '#DYNAMIC' $CONFIG | awk '{print $2}' | cut -f1 -d ';')
if [ "$IP" != "$IP_OLD" ]
then
NGINX_STATUS=$(nginx -t 2>&1 | tail -n 1 | awk '{print $7}')
2022-06-02 00:36:52 +05:00
if [ "$NGINX_STATUS" = "successful" ]
2022-06-02 00:30:16 +05:00
then
sed -i "s/$IP_OLD/$IP/" $CONFIG
systemctl restart nginx
else
2022-06-02 20:47:44 +05:00
echo nginx test failed
2022-06-02 00:30:16 +05:00
fi
else
2022-06-02 20:47:44 +05:00
echo IP IS SAME
2022-06-02 00:30:16 +05:00
fi