IPUPDATE: Difference between revisions
Jump to navigation
Jump to search
(Created page with "<pre> #!/bin/sh if [ !-d /root/scripts/IPINFO ]; then mkdir -p /root/scripts/IPINFO fi if [ -e /root/scripts/IPINFO/ipaddr ]; then OLDIP=$(cat /root/scripts/IP...") |
No edit summary |
||
Line 1: | Line 1: | ||
<pre> | <pre> | ||
#!/bin/sh | #!/bin/sh | ||
if [ !-d /root/scripts/IPINFO ]; then | if [[ ! -d /root/scripts/IPINFO ]]; then | ||
mkdir -p /root/scripts/IPINFO | mkdir -p /root/scripts/IPINFO | ||
fi | fi | ||
Line 19: | Line 19: | ||
OLDGW="" | OLDGW="" | ||
fi | fi | ||
while [[ ! -n $CURIP || ! -n $CURBC || ! -n $CURGW ]]; do sleep 3 | while [[ ! -n $CURIP || ! -n $CURBC || ! -n $CURGW ]]; do | ||
CURIP=$(ip addr show dev eth0 | grep inet | head -1 | cut -f 6 -d " " | cut -f 1 -d \/) | |||
CURBC=$(ip addr show dev eth0 | grep inet | head -1 | cut -f 8 -d " " | cut -f 1 -d \/) | |||
CURGW=$(ip route | grep default | cut -f 3 -d " ") | |||
sleep 3 | |||
done | |||
if [[$CURIP != $OLDIP ]]; then | if [[ $CURIP != $OLDIP ]]; then | ||
for i in /root/scripts/iptables-restore /etc/ipsec.conf /etc/ipsec.secrets /etc/xl2tpd/xl2tpd.conf; do | for i in /root/scripts/iptables-restore /etc/ipsec.conf /etc/ipsec.secrets /etc/xl2tpd/xl2tpd.conf; do | ||
sed -i s/$OLDIP/$CURIP/g $i; | sed -i s/$OLDIP/$CURIP/g $i; | ||
Line 31: | Line 33: | ||
fi | fi | ||
if [[$CURBC != $OLDBC ]]; then | if [[ $CURBC != $OLDBC ]]; then | ||
for i in /root/scripts/iptables-restore /etc/ipsec.conf /etc/xl2tpd/xl2tpd.conf; do | for i in /root/scripts/iptables-restore /etc/ipsec.conf /etc/xl2tpd/xl2tpd.conf; do | ||
sed -i s/$OLDBC/$CURBC/g $i; | sed -i s/$OLDBC/$CURBC/g $i; | ||
Line 37: | Line 39: | ||
fi | fi | ||
if [[$CURGW != $OLDGW ]]; then | if [[ $CURGW != $OLDGW ]]; then | ||
for i in /root/scripts/iptables-restore /etc/ipsec.conf /etc/xl2tpd/xl2tpd.conf; do | for i in /root/scripts/iptables-restore /etc/ipsec.conf /etc/xl2tpd/xl2tpd.conf; do | ||
sed -i s/$OLDGW/$CURGW/g $i; | sed -i s/$OLDGW/$CURGW/g $i; | ||
Line 46: | Line 48: | ||
echo -n "$CURBC" > /root/scripts/IPINFO/bcast | echo -n "$CURBC" > /root/scripts/IPINFO/bcast | ||
echo -n "$CURGW" > /root/scripts/IPINFO/gateway | echo -n "$CURGW" > /root/scripts/IPINFO/gateway | ||
</pre> | </pre> |
Revision as of 22:38, 2 October 2014
#!/bin/sh if [[ ! -d /root/scripts/IPINFO ]]; then mkdir -p /root/scripts/IPINFO fi if [ -e /root/scripts/IPINFO/ipaddr ]; then OLDIP=$(cat /root/scripts/IPINFO/ipaddr) else OLDIP="" fi if [ -e /root/scripts/IPINFO/bcast ]; then OLDBC=$(cat /root/scripts/IPINFO/bcast) else OLDBC="" fi if [ -e /root/scripts/IPINFO/gw ]; then OLDGW=$(cat /root/scripts/IPINFO/gateway) else OLDGW="" fi while [[ ! -n $CURIP || ! -n $CURBC || ! -n $CURGW ]]; do CURIP=$(ip addr show dev eth0 | grep inet | head -1 | cut -f 6 -d " " | cut -f 1 -d \/) CURBC=$(ip addr show dev eth0 | grep inet | head -1 | cut -f 8 -d " " | cut -f 1 -d \/) CURGW=$(ip route | grep default | cut -f 3 -d " ") sleep 3 done if [[ $CURIP != $OLDIP ]]; then for i in /root/scripts/iptables-restore /etc/ipsec.conf /etc/ipsec.secrets /etc/xl2tpd/xl2tpd.conf; do sed -i s/$OLDIP/$CURIP/g $i; done fi if [[ $CURBC != $OLDBC ]]; then for i in /root/scripts/iptables-restore /etc/ipsec.conf /etc/xl2tpd/xl2tpd.conf; do sed -i s/$OLDBC/$CURBC/g $i; done fi if [[ $CURGW != $OLDGW ]]; then for i in /root/scripts/iptables-restore /etc/ipsec.conf /etc/xl2tpd/xl2tpd.conf; do sed -i s/$OLDGW/$CURGW/g $i; done fi echo -n "$CURIP" > /root/scripts/IPINFO/ipaddr echo -n "$CURBC" > /root/scripts/IPINFO/bcast echo -n "$CURGW" > /root/scripts/IPINFO/gateway