rubence
February 20, 2016, 7:36pm
1
i’ve some files each starting with “mikrotik” prefix, like mikrotik-1234, mikrotik-5678 and so on.need to do a loop scripting like "for each $filename do /tool fetch $filename " so that i can send all files through ftp with same name with help of /tool fetch command
thanks in advnace
PaulsMT
February 22, 2016, 12:19pm
2
:local filename;
:foreach file in=[/file find where name~“mikrotik”] do={
:set $filename [/file get $file name];
/tool fetch src-path=$filename …
}
rubence
February 22, 2016, 3:21pm
3
thanks a lot . its working..
arammal
September 4, 2020, 9:36am
4
Hello,
Could you please provide me your script, as Im working on my own with no success, below my script:
:local filename;
:foreach filename in=[/file find where name~“routeros-mipsbe”] do={
:set $filename [/file get $file name];
/tool fetch mode=ftp upload=no address=x.x.x.x port=x user=“x” password=“x” src-path=$filename dst-path=“routeros-mipsbe-6.47.2.npk” keep-result=yes
}
msatter
September 4, 2020, 12:04pm
5
Hello,
Could you please provide me your script, as Im working on my own with no success, below my script:
:local filename;
:foreach filename in=[/file find where name~“routeros-mipsbe”] do={
:set $filename [/file get $file name];
/tool fetch mode=ftp upload=no address=x.x.x.x port=x user=“x” password=“x” src-path=$filename dst-path=“routeros-mipsbe-6.47.2.npk” keep-result=yes
}
Hey topic hopper!
http://forum.mikrotik.com/t/syntax-to-wildcard-the-rest-of-path/142735/1
:set $filename [/file get $file name];
/tool fetch ...................dst-path="routeros-mipsbe-6.47.2.npk" keep-result=yes
:set $filename [/file get $file name];
/tool fetch .............dst-path="$filename keep-result=yes
You don’t know in advance what the source filename is so you also don’t know the destination name.
arammal
September 4, 2020, 3:26pm
6
also tried with no success,
msatter
September 4, 2020, 4:56pm
7
I only brought forward a logical error.
The next error you make is using foreach and it’s counter is changed in the loop to an other value.
Thirdly, you can’t use variable names that are already used by RouterOS.
You should check you code better and make you variable names unique.
msatter
September 4, 2020, 5:05pm
8
{
:local fileName;
:foreach fileCounter in=[/file find where name~"routeros-mipsbe"] do={
:set $fileName [/file get $fileCounter name];
/tool fetch mode=ftp upload=no address=x.x.x.x port=x user="x" password="x" src-path=$fileName dst-path=$fileName keep-result=yes
}
I can’t test it and it is way over my head how it works.
arammal
September 4, 2020, 5:17pm
9
thank you for your help!
My goal is to write a script to get packages from remote RouterOS(x.x.x.x) using /tool fetch mode=ftp…, in src-path I need to wildcard the rest of name of package, example if package with name “routeros-mipsbe-6.47.2.npk” i need only to put in src-path “routeros-mipsbe-WHATEVER”, what shall i use as expression/character in Mikrotik script to express the WHATEVER?
Please note that this script (/tool fetch mode=ftp upload=no address=x.x.x.x port=x user=“x” password=“x” src-path=“/routeros-mipsbe-6.47.2.npk” dst-path=“routeros-mipsbe-6.47.2.npk” keep-result=yes;) working well!!
msatter
September 4, 2020, 7:48pm
10
My adaptation needs a extra “}” in the last line.
You have to check what value is in $fileName:
:set $fileName [/file get $fileCounter name]; :put $fileName;
So you can check if yuo have to also a “/” in front of the src-path
src-path=“/$fileName”
msatter
September 5, 2020, 6:50am
11
{
:local fileName
:foreach fileCounter in=[/file find name~"routeros-mipsbe"] do={
:set $fileName [/file get $fileCounter name]
:do {
/tool fetch mode=ftp upload=no address=x.x.x.x port=x user="x" password="x" src-path="/$fileName" dst-path="/$fileName" keep-result=yes
:log info "Copied file: $fileName"
} on-error={ :log warning "Matched file $fileName has not been copied."}
}}