I have a problem with an concatenate operation in a script that I can't understand nor solve.
To automatically set up VPN routers with specific IPs I wrote a script where I enter the specific IP and MAC segments into variables.
The variables then are used on different concatenate commands in the script.
I tested every command of the script one by one in the terminal (connected via Winbox) and it worked.
However, if I run the script one concatenate operation is not performed correctly.
It looks like this:
my variable declaration:
Code: Select all
:global myIP
:global myMAC
:global myName
:set myIP "20.33"
:set myMAC "20:00:33"
:set myName "w20033"
/interface ovpn-client
add name=ovpn comment=VPN mac-address=[ :put ("02:D7:5E:".$myMAC) ] \
connect-to=secret port=secret user=user1 profile=default-encryption \
certificate=[ :put ($myName.".ag") ] cipher=aes256
The concatenate operation that didn't work:
/ip address
add address=[:put ("172." . $myIP . ".1/24")] network=[:put ("172." . $myIP . ".0")] interface=ovpn
The output is:
172..1/24
invalid input for argument address
It ignores my variable in between the two strings.
As I said, if I copy paste the exact same codeline into the terminal and execute it, it works. The IPs 172.20.33.1/24 and 172.20.33.0 are added.
I then tried several variations of the code:
Code: Select all
add address=[:put "172.$myIP.1/24"] network=[:put ("172.$myIP.0")] interface=ovpn
add address=[:put ("172.".$myIP.".1/24")] network=[:put ("172.".$myIP.".0")] interface=ovpn #no whitespace between "."
I also tried nested :put operations within the :put operations but that didn't work in the terminal.
I have no idea anymore. How can it work in the terminal but not when ran in a script?
Any ideas?