Community discussions

MikroTik App
 
electravis
Member Candidate
Member Candidate
Topic Author
Posts: 274
Joined: Tue Jan 26, 2010 12:06 am

script to write to file

Tue Feb 20, 2018 9:00 pm

So I am trying tomake a script that will write to a file all of the hostpot user info. From what I can tell I would have to do a print detail, print stats, and print status to get all the info i need and then merge them together in database somewhere.
If I use the API this is possible but API can not be run locally from the mikrtoik?

Any thoughts how to accomplish this with out having to write 3 files and then merger them together? I want it to be able to be run form the tik locally and then pushed to the server vs the server polling the mikrotik for the data through an API.

Thanks
 
User avatar
boen_robot
Forum Guru
Forum Guru
Posts: 2400
Joined: Thu Aug 31, 2006 4:43 pm
Location: europe://Bulgaria/Plovdiv

Re: script to write to file

Tue Feb 20, 2018 9:21 pm

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.

Who is online

Users browsing this forum: No registered users and 29 guests