script to write to file

If the router is powerful enough, you could run a VM (using MetaRouter or KVM for x86), and run an API application from there. That’s as local as you can get with that.

If not that, you could collect all of your output in a single variable, and then output the variable to a file that you then send. See this topic for an example of outputting data reliably in a API-ish form (just :set to a variable instead of :put as terminal output), for a more structured DB input.

To output a variable to a file, just run any print with a file argument to create the file and “:delay 2s” for a flush (or skip those two steps if there’s already a file from last upload or you’ve manually uploaded one to the router with FTP, Winbox or whatever). Then use “/file set myFile contents=$myContent” to modify that file, and “:delay 2s” for the contents to be written before finally uploading the new file.