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:
- Create file routeros.script with content:
/inreface print
:log info message=“test”
:log info message=“line 3” - 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?