How can I write script output to a file

I’m running Mikrotik 3.25 and have this script bellow.

:local x 0
:foreach i in=[/interface wireless registration-table find] do {
	:put ($x . " :: " . [/interface wireless registration-table get $i interface] . " :: " . [/interface wireless registration-table get $i mac-address] . " :: " . [/interface wireless registration-table get $i last-ip] . " :: " . [/interface wireless registration-table get $i signal-strength])
	:set x ($x + 1)
}

I want to output result of this script to a file and my PHP script get it by ftp to get some information about clients.

How can I do it?

Thank you.

For files that already exist you can set the content as below:

[admin@MikroTik] > /file pri where name="test.txt"
 # NAME       TYPE     SIZE     CREATION-TIME
57 test.txt    .txt file  0          jun/17/2010 14:05:42
[admin@MikroTik] > :local test "test"; /file set [/file find name="test.txt"] contents=$test;
[admin@MikroTik] > /file pri where name="test.txt"
 # NAME       TYPE     SIZE     CREATION-TIME
57 test.txt    .txt file  4          jun/17/2010 14:06:38
[admin@MikroTik] >

Variables can’t be larger than 4096 bytes so that is the maximum amount of information you can write to a file.

But you should also look into the API, or SNMP. There’s a PHP library and you could just get this information directly without having to write to a file and fetch it via FTP.

But can I append to a file?

I’ll take a look at API.

Thank you.

No you can’t append to file. Only way is to read whole content from the file add your data and then write whole content back to file.

No you can’t append to file. Only way is to read whole content from the file add your data and then write whole content back to file.

solution?

However how to output (for example variable) to file which DO NOT EXISTS yet? I am trying to achieve this many hours. Thanks.