Append script by API

Hello all.
I wrote a PHP script (with using library Denis Basta (http://wiki.mikrotik.com/wiki/API_PHP_class)).
I want append RouterOS script by the API from php script. RouterOS script multiple lines (two and more lines).
How to send a special symbols new line (\n) and cartrige return (\r) ?
I try use a php function addcslashes($routeros_script, “\r\n”), but has no effect.
What i do:

  1. Create file routeros.script with content:
    /inreface print
    :log info message=“test”
    :log info message=“line 3”
  2. Make php script with content:
    $api = new routeros_api();
    $source = file_get_contents(“routeros.script”);
    $api->comm(“/system/script/add”, [ ‘name’ => ‘test’, ‘source’ => addcslashes(“{ $source }”, “\r\n”) ]);

From debug info of class routeros_api:
<<< [18] /system/script/add
<<< [10] =name=test
<<< [83] =source={ /inreface print\n:log info message=“test”\n:log info message=“line 3”\n }

[5/5] bytes read.
[5, 9]!done
[7/7] bytes read.
[7, 1]=ret=*8

Next i see to mikrotik by Winbox system->scripts->test:
{ /inreface print\n:log info message=“test”\n:log info message=“line 3”\n }
One line with “\n” symbols.

If i not using addcslashes function in my php script, then each line sends as a command:
<<< [18] /system/script/add
<<< [10] =name=test
<<< [23] =source=/inreface print
<<< [24] :log info message=“test”
<<< [26] :log info message=“line 3”
<<< [0]

[5/5] bytes read.
[5, 9]!done
[7/7] bytes read.
[7, 1]=ret=*B

The same script from mikrotik after send:
/inreface print

One line

what am I doing wrong?

I have the same problemas

Any idea?

I have the same problem

Any idea?

I have not tried exactly what you’re doing, but I solved the same problem by using a pre-loaded script to retrieve a configuration snippet via fetch and then import it. Then I just use the API to execute the pre-loaded script.

Obviously, you can then load all kinds of things simply by changing what I’m retrieving.

(I’m using pear2_net_routeros API.)