Update for better script method
This commit is contained in:
parent
8f919a1deb
commit
b41b919d4c
@ -1,26 +1,23 @@
|
|||||||
#!/bin/vbash
|
#!/bin/vbash
|
||||||
source /opt/vyatta/etc/functions/script-template
|
source /opt/vyatta/etc/functions/script-template
|
||||||
|
|
||||||
# create copies of config for modification and backup
|
# get current public IP
|
||||||
cp /config/config.boot /config/config.new
|
NEW_IP=$(show interfaces pppoe pppoe1 | grep "inet\s" | cut -d ' ' -f 6)
|
||||||
cp /config/config.boot /config/backups/config.bk-$(date +%Y-%m-%d)
|
# get old public IP
|
||||||
|
OLD_IP=$(show nat destination rules | grep 1100 | head -1 | tr -s ' ' | cut -d' ' -f 3)
|
||||||
|
|
||||||
|
|
||||||
|
show configuration commands | grep $OLD_IP | sed --expression="s/$OLD_IP/$NEW_IP/" > ipupdate.tmp
|
||||||
|
|
||||||
# switch mode to config
|
|
||||||
configure
|
configure
|
||||||
|
|
||||||
# get current public IP
|
source ipupdate.tmp
|
||||||
NEW_IP=$(run show interfaces pppoe pppoe1 | grep "inet\s" | cut -d ' ' -f 6)
|
|
||||||
# get old public IP
|
|
||||||
OLD_IP=$(run show nat destination rules | grep 1100 | head -1 | tr -s ' ' | cut -d' ' -f 3)
|
|
||||||
|
|
||||||
# edit the config.new file
|
|
||||||
sed -i "s/$OLD_IP/$NEW_IP/" /config/config.new
|
|
||||||
|
|
||||||
# apply the new config
|
|
||||||
load /config/config.new
|
|
||||||
{ # try commit, save, exit
|
{ # try commit, save, exit
|
||||||
commit && save && exit
|
commit && save && exit
|
||||||
} || { # catch, exit discard and create a very basic error file
|
} || { # catch, exit discard and create a very basic error file
|
||||||
exit discard
|
exit discard
|
||||||
echo "Script failed. Write some real error handling."
|
echo "Script failed. Write some real error handling."
|
||||||
}
|
}
|
||||||
|
|
||||||
|
rm ipupdate.tmp
|
||||||
|
Loading…
Reference in New Issue
Block a user