Hello, just working on a simple script to test out a non-critical ipsec tunnel between 2 offices.
The first part of the script runs fine from terminal or via winbox (removing all code from the change-ipsec-ip script so I can test without the secondary error) but when I try to run the second section on its own to test it I get
“syntax error (line 1 column 33)”
If I try reproducing this error by copying and pasting the lines into terminal I get no issues??
Script Name: check-ipsec-ip
:global IPsecintname "EdoTun"
:global IPsecdnsname "example.dyndns.org"
:global IPsecnetport "/32:500"
:global newIPsecip [:resolve $IPsecdnsname]
:global currentIPsecip [/interface ipip get $IPsecintname remote-address]
:if ($currentIPsecip != $newIPsecip) do={/system script run change-ipsec-ip}
Script Name: change-ipsec-ip
/interface ipip set [find name=$IPsecintname] remote-address=$newIPsecip
/ip ipsec peer set [find address=$currentIPsecip.$IPsecnetport address=($newIPsecip.$IPsecnetport)
Any ideas what is going wrong here?
Regards
Here is one issue:
:global currentIPsecip [/interface ipip get $IPsecintname remote-address]
You can’t directly access a property without first finding it. I know, not as easy as one would hope.
:global currentIPsecip [/interface ipip get [/interface ipip find name=$IPsecintname] remote-address]
I didnt test that - from memory.
Thx,
Sam
That section works fine thou, its the last 2 lines which give me the error
mrz
May 14, 2008, 8:39am
4
Is it on v3.x or 2.9?
If 3.x then
Script ‘change-ipsec-ip’ should look like this:
:global IPsecintname;
:global IPsecdnsname;
:global IPsecnetport;
:global newIPsecip;
:global currentIPsecip;
/interface ipip set [find name=$IPsecintname] remote-address=$newIPsecip
/ip ipsec peer set [find address=$currentIPsecip.$IPsecnetport address=($newIPsecip.$IPsecnetport)
Variables must be defined before usage in v3.x
Thanks heaps!
This is my script (for the second part)
:global IPsecintname;
:global IPsecdnsname;
:global IPsecnetport;
:global newIPsecip;
:global currentIPsecip;
/interface ipip set [find name=$IPsecintname] remote-address=$newIPsecip
/ip ipsec peer set [find address=$currentIPsecip.$IPsecnetport] address=($newIPsecip.$IPsecnetport)