The maximum size of a read/written file.

Personally I will go with approach: In loop where records are appended to variable for file save, before append record to that variable I will first check size of that variable and if that length of that variable + length of record variable exceeds 4K then I will write current content value into file segment, then assign current record variable into that variable. File segment counter needs to be raised each time when file is saved. At the end you will have files like: sms.txt.1, sms.txt.2, sms.txt.3… which can be merged on other system where are downloaded.

Why consider the volume of a variable, if everything is well written to a file without it. Have you seen my example above? There is exactly the same principle as you described, only without checking the volume of the variable.
I do not argue, the example is not very well designed, but it was one of the first scripts that I wrote and I published it here just so that the @rextended understood what I was talking about.

Well that is not exactly, that part is crucial if you don’t want to reach 4k limit. Topic is The maximum size of a read/written file. which is actually limit of variable that contains content of a file.

I saw your script example, yes it contains loop for writing file segments, but it is lacking logic which I mentioned.



execute "/system script get \"sms.txt\" source" file="sms.txt"

I don’t do scripting anymore but this should write to the file. If you come up with the correct commands it should write to the file sms.txt

@DyadyaGenya try with this

:local output ( [ /interface lte at-chat lte1 wait=yes input="AT+CMGL=4" as-value ]->"output" )
:local lenOutput [:len $output]
:local splitSize 4095
:local offset 0
:local part 1

:while ($offset < $lenOutput) do={
  :local nameFile ("sms".$part.".txt")

  :if (($offset + $splitSize) > $lenOutput) do={
    /file add name=$nameFile contents=[:pick $output $offset $lenOutput]
    :set offset $lenOutput
  } else={
    /file add name=$nameFile contents=[:pick $output $offset ($offset + $splitSize)]
    :set offset ($offset + $splitSize)
  }

  :set part ($part + 1)
}

@optio Why still self limit to 4096 bytes!? Many people here walked into this limitation for many years and some found little gems in RouterOS which works around problems. One of those is “:execute”

Lets keep it simple, this will store the output of a command or script to a file like it was display in you screen.

:execute "/ip/route/export" file="test"

It adds the default extension “txt” to the filename, here is that “test”

You can find more about :execute: https://wiki.mikrotik.com/wiki/Manual:Scripting#Global_commands

Ok, from DyadyaGenya script example correct answer will be then

:execute ":put ([/interface lte at-chat lte1 wait=yes input=\"AT+CMGL=4\" as-value ]->\"output\")" file=sms.txt

This may answer https://forummikrotik.ru/viewtopic.php?p=89403#p89403 :slight_smile:

LOL. About the same...

Всё написано выше. Имеющий глаза - увидит

(Google tells me, that means "Everything is written above. Those who have eyes will see.")

What does it have to do with it, I wanted him to specify it, if he wanted...
If you look closely you'll see that the Uncle Женя lives in Chernihiv, and was born on January 17.. :laughing: (Женя жарт... :wink: )
I don't put the year, if he wants he can put it there... :laughing:

No, I wrote "It adds the default extension “txt” to the filename, here is that “test” ".

:execute ":put ([/interface lte at-chat lte1 wait=yes input=\"AT+CMGL=4\" as-value ]->\"output\")" file="sms"

Works also with .txt extension in file param, then it will not append .txt to filename.

In fact, both options work. And if you tell me how to read the received files, then this will be an almost ideal solution. I write “almost” because for some reason (maybe it’s something wrong with me) after rebooting the router, the file disappears. It has to be copied to another location or renamed.

That depends on the type of router. Unfortunately, MikroTik has missed the chance of defining standard paths of persistent/volatile files.
Now, you will have to check yourself and use a path suitable for your router type and configuration.

Not overhere on ROS 7.10

I’m also on 7.10

> /system/routerboard/print 
  routerboard: yes
  model: D53G-5HacD2HnD
  serial-number: XXXXXXXX
  firmware-type: ipq4000L
  factory-firmware: 7.1beta5
  current-firmware: 7.10
  upgrade-firmware: 7.10
> :execute ":put ([/interface lte at-chat lte1 wait=yes input=\"AT+CMGL=4\" as-value ]->\"output\")" file="sms.txt"

sms_file.png

If you want to restore the stored data or transfer to a differen router then selective path exporting and exporting is the simple way.

I don’t know how thatworks with LTE or SMS because I don’t have that.

In this posting is mentioned that extension does not need to be RSC.

http://forum.mikrotik.com/t/the-maximum-size-of-a-read-written-file/167507/36

*** see my next post ***

Already explained above http://forum.mikrotik.com/t/the-maximum-size-of-a-read-written-file/167507/1 and system note can be used as workaround. You can also provide file over http and use chunked download with fetch tool, also you have post with script by rextended http://forum.mikrotik.com/t/how-to-download-only-one-piece-of-file-at-a-time-with-tool-fetch-and-put-it-inside-a-variable/151020/1

you can use flash of usb storage for persistence, depends on device, to save it on flash use

file="flash/sms"