Greetings - I’m just getting going with RouterOS scripting and I’m challenged to get the syntax right to run a script from a file. I’ve uploaded the script via ftp as test.txt, but can’t figure out how to specify the file as the source of the script.
First I always check if the script will run on the version of ROS i am using, to test the script for syntax errors you can in terminal put { at the start and } at the end of the script also you can test from terminal /system script use print command and it will show any syntax errors, a least then after the tests and any corrections to syntax errors you will have a working script. hope this will be of some help to you.
Hi. I do not understand – you have this file test.rsc in the / directory. Now I do not understand what you mean by in terminal putting { before and } after the script and why it would not execute the script?
Any way to import the script into the system script interface, so I could schedule it or whatever?
Name your file as a .rsc file such as thescript.rsc".
Upload file
From terminal run "/import file-name=“thescript.rsc”
This will then essentially “run” whatever code you had in the file.
If you wanted the uploaded file to ‘create a script’ for you that you can run again later the .rsc file itself must create the required script. Here’s an example:
/system script
# Remove old script with same name if it exists
:if ([:len [/file find name="TestScript"]] > 0) do={remove ([/system script find name~"TestScript"]);}
#Add new script
add name=TestScript policy=ftp,reboot,read,write,test,winbox,password,sensitive source="\
# Everything from this point is part of the script called TestScript
# log a warning as example
/log warning \"When this script is called it will log a warning in the system log\"
# End of script
"
Now, if you wanted the above to automatically execute when you ftp it - simply name it thescript.auto.rsc.
Once uploaded the file will then automatically execute and create a script called “TestScript” which will then be available for you to run on the router.
Thanks much – just one more question – what did the previous poster mean to say that in terminal you could put { and } around the script to prevent execution – I do not understand this.