Community discussions

MikroTik App
 
karaYusuf
Frequent Visitor
Frequent Visitor
Topic Author
Posts: 54
Joined: Wed Oct 12, 2022 11:07 am

Why does the second script not run?

Thu Dec 08, 2022 4:35 pm

Hello everyone,
i made a script, which is swapping the functions of wlan1 and wlan2:
#swaping mac-address of wlan1 and wlan2
/interface/wireless
set [ find default-name=wlan1 ] mac-address=xxx

/interface/wireless
set [ find default-name=wlan2 ] mac-address=xxx



#disabling wlan1(2GHz) as station-mode
/interface/wireless
set [ find default-name=wlan1 ] band=2ghz-b/g/n \
    country=germany disabled=no frequency=auto mode=ap-bridge \
    installation=any default-authentication=yes \
    security-profile=default ssid=xxx
/interface bridge port add bridge=bridgeLAN interface=wlan1

/interface/wireless/connect-list/disable [find interface=wlan1]

/interface/list/member/remove [find interface=wlan1]



#enabling wlan2(5GHz) as station-mode
/interface wireless
set [ find default-name=wlan2 ] band=5ghz-a/n/ac channel-width=20/40/80mhz-XXXX \
    country=germany disabled=no frequency=auto \
    mode=station \
    default-authentication=no ssid="" \
    station-roaming=enabled installation=outdoor
/interface bridge port remove [find interface=wlan2]

/interface wireless connect-list
add interface=wlan2 signal-range=-75..120 allow-signal-out-of-range=1s connect=yes disabled=no security-profile=xxx ssid=xxx

/interface list member add list=WAN interface=wlan2

/ip/dhcp-client/remove [find interface=wlan1]
/ip/dhcp-client/add interface=wlan2 



#automatisation for using lte-modem
/system script add dont-require-permissions=no name=wlan2-autoActivate owner=admin policy=\
    ftp,reboot,read,write,policy,test,password,sniff,sensitive,romon source=":\
    if ([/interface print count-only where name=lte1] = 0) do={\r\
    \n /interface enable [find where name=wlan2];\r\
    \n} else={\r\
    \n:log info \"Error \";\r\
    \n}"

/system scheduler add interval=10s name=autoActivate on-event=wlan2-autoActivate start-time=startup

/system script add dont-require-permissions=no name=wlan2-autoDeactivate owner=admin policy=\
    ftp,reboot,read,write,policy,test,password,sniff,sensitive,romon source=":\
    if ([/interface print count-only where name=lte1] = 1) do={\r\
    \n /interface disable [find where name=wlan2];\r\
    \n} else={\r\
    \n:log info \"Error \";\r\
    \n}"

/system scheduler add interval=10s name=autoDeactivate on-event=wlan2-autoDeactivate start-time=startup
I just put that code in the files and use the import command to get the new settings..
So this is working on one specific hapac2-Router.
I decided to make this script working on every router pulling the mac-addresses of the wifi-interfaces and swapping them.
I came up with the following code:
#getting variables
:global getWlan2 [interface wireless get wlan2 ssid]
:global getMac1 [interface get wlan1 mac-address]
:global getMac2 [interface get wlan2 mac-address]



#swaping mac-address of wlan1 and wlan2
/interface/wireless
set [ find default-name=wlan1 ] mac-address=$getMac2

/interface/wireless
set [ find default-name=wlan2 ] mac-address=$getMac1



#disabling wlan1(2GHz) as station-mode
/interface/wireless
set [ find default-name=wlan1 ] band=2ghz-b/g/n \
    country=germany disabled=no frequency=auto mode=ap-bridge \
    installation=any default-authentication=yes \
    security-profile=default ssid=$getWlan2
/interface bridge port add bridge=bridgeLAN interface=wlan1

/interface/wireless/connect-list/disable [find interface=wlan1]

/interface/list/member/remove [find interface=wlan1]



#enabling wlan2(5GHz) as station-mode
/interface wireless
set [ find default-name=wlan2 ] band=5ghz-a/n/ac channel-width=20/40/80mhz-XXXX \
    country=germany disabled=no frequency=auto \
    mode=station \
    default-authentication=no ssid="" \
    station-roaming=enabled installation=outdoor
/interface bridge port remove [find interface=wlan2]

/interface wireless connect-list
add interface=wlan2 signal-range=-75..120 allow-signal-out-of-range=1s connect=yes disabled=no security-profile=xxx ssid=xxx

/interface list member add list=WAN interface=wlan2

/ip/dhcp-client/remove [find interface=wlan1]
/ip/dhcp-client/add interface=wlan2 



#automatisation for using lte-modem
/system script add dont-require-permissions=no name=wlan2-autoActivate owner=admin policy=\
    ftp,reboot,read,write,policy,test,password,sniff,sensitive,romon source=":\
    if ([/interface print count-only where name=lte1] = 0) do={\r\
    \n /interface enable [find where name=wlan2];\r\
    \n} else={\r\
    \n:log info \"Error \";\r\
    \n}"

/system scheduler add interval=10s name=autoActivate on-event=wlan2-autoActivate start-time=startup

/system script add dont-require-permissions=no name=wlan2-autoDeactivate owner=admin policy=\
    ftp,reboot,read,write,policy,test,password,sniff,sensitive,romon source=":\
    if ([/interface print count-only where name=lte1] = 1) do={\r\
    \n /interface disable [find where name=wlan2];\r\
    \n} else={\r\
    \n:log info \"Error \";\r\
    \n}"

/system scheduler add interval=10s name=autoDeactivate on-event=wlan2-autoDeactivate start-time=startup
My problem is that this code just do not run. Giving me the same setting as I would have never used the import command. I do not see any syntax-mistakes.
It would be very great if there is someone knowing why it does not run.
Thank you for helping me.
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 11982
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: Why does the second script not run?

Fri Dec 09, 2022 12:40 am

You need one temporary MAC to swap MACs or when you set one identical MAC RouterOS you can lock or loop something...
# getting variables
/interface wireless
:global getMac1  [get [find where default-name=wlan1] mac-address]
:global getMac2  [get [find where default-name=wlan2] mac-address]

# prevent duplicate MACs when set on wlan1 the same MAC of wlan2
set [find where default-name=wlan2] mac-address=BA:DB:AD:BA:DB:AD

# swaping mac-address of wlan1 and wlan2
set [find where default-name=wlan1] mac-address=$getMac2
set [find where default-name=wlan2] mac-address=$getMac1

For the rest, I didn't understand anything.

Explain the end goal, not the intermediate steps....
 
karaYusuf
Frequent Visitor
Frequent Visitor
Topic Author
Posts: 54
Joined: Wed Oct 12, 2022 11:07 am

Re: Why does the second script not run?

Wed Dec 14, 2022 11:56 am

You need one temporary MAC to swap MACs or when you set one identical MAC RouterOS you can lock or loop something...
# getting variables
/interface wireless
:global getMac1  [get [find where default-name=wlan1] mac-address]
:global getMac2  [get [find where default-name=wlan2] mac-address]

# prevent duplicate MACs when set on wlan1 the same MAC of wlan2
set [find where default-name=wlan2] mac-address=BA:DB:AD:BA:DB:AD

# swaping mac-address of wlan1 and wlan2
set [find where default-name=wlan1] mac-address=$getMac2
set [find where default-name=wlan2] mac-address=$getMac1

For the rest, I didn't understand anything.

Explain the end goal, not the intermediate steps....
The rest is not understandable because the script on top is just an adding script to another script.
You solved my problem :) I thank you alot for your help and I am sorry for the late reply.

Who is online

Users browsing this forum: mhenriques and 20 guests