Community discussions

 
AllisonF
just joined
Topic Author
Posts: 6
Joined: Wed Oct 31, 2018 7:29 pm

Script only works in terminal, not by GUI or scheduler

Fri Dec 28, 2018 8:48 pm

Hello everyone,

I'm trying to make a startup script to run and automatically change some router settings and this script works perfectly if I run it from the terminal, but if the GUI "run script" button is pressed or the scheduler runs the script, the run count increases, but the script does not complete.

I have the following script:

{
{/interface wireless
set [ find default-name=wlan1 ] band=2ghz-b/g/n channel-width=20/40mhz-Ce \
disabled=no distance=indoors frequency=auto mode=ap-bridge ssid=\
CHANGEME wireless-protocol=802.11
set [ find default-name=wlan2 ] band=5ghz-a/n/ac channel-width=20/40/80mhz-Ceee \
disabled=no distance=indoors frequency=auto mode=ap-bridge ssid=\
CHANGEME_5G_AC_Only wireless-protocol=802.11}
{/interface wireless security-profiles
set [ find default=yes ] authentication-types=wpa-psk,wpa2-psk mode=dynamic-keys supplicant-identity=\
MikroTik wpa-pre-shared-key=CHANGEME wpa2-pre-shared-key=CHANGEME}}


{/user group set 1 skin=restech
/user group set 0 skin=customer}

{/int wireless
set 0 name=wlan1
set 1 name=wlan2} <------------------------------- With some tests, I have determined that all settings above this line apply correctly, so this is where it breaks

{/int bridge port
remove 4,5
add bridge=bridge interface=wlan1
add bridge=bridge interface=wlan2}

{/system ident set name=CHANGEME}

{/int eth reset-mac-address 0,1,2,3,4}

{/sys script rem program}
}


Any idea what I'm doing wrong here?

Thanks!
 
AllisonF
just joined
Topic Author
Posts: 6
Joined: Wed Oct 31, 2018 7:29 pm

Re: Script only works in terminal, not by GUI or scheduler

Fri Dec 28, 2018 10:31 pm

I actually solved my issue. It was due to the nature of the dynamic numbering system. You need print statements to cache your numbers as referable variables.

The working script was as follows:

{

{/interface wireless
set [ find default-name=wlan1 ] band=2ghz-b/g/n channel-width=20/40mhz-Ce \
disabled=no distance=indoors frequency=auto mode=ap-bridge ssid=\
CHANGEME wireless-protocol=802.11
set [ find default-name=wlan2 ] band=5ghz-a/n/ac channel-width=20/40/80mhz-Ceee \
disabled=no distance=indoors frequency=auto mode=ap-bridge ssid=\
CHANGEME_5G_AC_Only wireless-protocol=802.11}
{/interface wireless security-profiles
set [ find default=yes ] authentication-types=wpa-psk,wpa2-psk mode=dynamic-keys supplicant-identity=\
MikroTik wpa-pre-shared-key=CHANGEME wpa2-pre-shared-key=CHANGEME}


{/user group
print
set 1 skin=restech
set 0 skin=customer}

{/int wireless
print
set 0 name=wlan1
set 1 name=wlan2}



{/int bridge port
print
remove 4,5
add bridge=bridge interface=wlan1
add bridge=bridge interface=wlan2}

{/system ident set name=CHANGEMETESTINGSTUFF}

{/int eth reset-mac-address 0,1,2,3,4}

{/sys script
pr
rem 0}
}


Thanks
Last edited by AllisonF on Sat Dec 29, 2018 12:40 am, edited 1 time in total.
 
joegoldman
Member
Member
Posts: 492
Joined: Mon May 27, 2013 2:05 am

Re: Script only works in terminal, not by GUI or scheduler

Fri Dec 28, 2018 11:01 pm

Thanks for following up with solution - thats actually a very peculiar behaviour which would be easy to overlook.
 
User avatar
eworm
Member
Member
Posts: 392
Joined: Wed Oct 22, 2014 9:23 am
Location: Oberhausen, Germany
Contact:

Re: Script only works in terminal, not by GUI or scheduler

Sat Dec 29, 2018 11:54 pm

You should not (never ever!) use any print and index in your scripts. Things will break badly if items are numbered different for what ever reason. Instead of this bad code:
/int bridge port
print
remove 4,5
You should use something like this:
/int bridge port
remove [ find where interface=wlan1 ]
remove [ find where interface=wlan2 ]
I guess that meets your needs? But it will not break if wlan1 and wlan2 are not numbered 4 and 5 - in contrast to your code.
Manage RouterOS scripts and extend your devices' functionality: RouterOS Scripts
 
AllisonF
just joined
Topic Author
Posts: 6
Joined: Wed Oct 31, 2018 7:29 pm

Re: Script only works in terminal, not by GUI or scheduler

Mon Dec 31, 2018 10:49 pm

You should not (never ever!) use any print and index in your scripts. Things will break badly if items are numbered different for what ever reason. Instead of this bad code:
/int bridge port
print
remove 4,5
You should use something like this:
/int bridge port
remove [ find where interface=wlan1 ]
remove [ find where interface=wlan2 ]
I guess that meets your needs? But it will not break if wlan1 and wlan2 are not numbered 4 and 5 - in contrast to your code.
That indeed meets my needs, though in my case, the script is to fix some things that result from using a backup config for the base unit on other units (trying to simplify configuration for customer deployment). As a result of the backup file always being the same, I was not in danger of the numbers changing, but in most cases I would have been. Those commands are super useful and I'll definitely use those going forward though. Thanks for the help!

Who is online

Users browsing this forum: No registered users and 4 guests