Community discussions

MikroTik App
 
alamdias
just joined
Topic Author
Posts: 15
Joined: Thu Aug 24, 2006 7:54 pm

Comma - Error in terminal send " "

Wed May 06, 2009 2:30 pm

Hi guys,

I´m From brazil.

I have a PHP script in PHP, above, one line:

passthru("$sshpass -p $srv_mkt_pwd ssh sagu-pro@$srv_mkt_ip \"/ip address print without-paging ; /ip address remove '$ips' \" ");

This is a part of script, the variable '$ips' is the name of the ARP, example 105-Markux-James

This line send to mikrotik:

/ip address remove 105-Markux-James

But, the caracter - in the line, is going RED and mikrotik show a error

[admin@SVNET] > /ip arp remove 105-
expected end of command (line 1 column 20)

The only way is type:

/ip address remove "105-Markux-James"

In PHP i dont now how to send " " inside de line. If i do, the PHP show a ERROR.

The Mikrotik is version 3.23

thnks in advance
 
User avatar
Chupaka
Forum Guru
Forum Guru
Posts: 8712
Joined: Mon Jun 19, 2006 11:15 pm
Location: Minsk, Belarus
Contact:

Re: Comma - Error in terminal send " "

Thu May 07, 2009 1:40 am

I think, you should double-escape the string, like

passthru("$sshpass -p $srv_mkt_pwd ssh sagu-pro@$srv_mkt_ip \"/ip address print without-paging ; /ip address remove \\\"$ips\\\" \" ");
 
alamdias
just joined
Topic Author
Posts: 15
Joined: Thu Aug 24, 2006 7:54 pm

Re: Comma - Error in terminal send " " [resolved]

Thu May 07, 2009 4:28 am

Hi. my english is poor !!

your answer is right. worked in parts

Look the other part of the script in php

After SQL select, the script runs, and write a temp file

$teste=shell_exec("$sshpass -p $srv_mkt_pwd ssh sagu-pro@$srv_mkt_ip /ip arp print without-paging | grep ';;; $id_pessoa-' > $file");
$handle = fopen($file,'r');
while ($linha = fgets($handle,1024)){
//echo "Deletar ".$linha."<br>";
$array_ips=explode(";;; ",$linha);
$ipsx=$array_ips[1];
$ips=substr_replace($ipsx ,"",-2); /// <<<<< added to remove 2 last caracters !!!
#GATEWAY CASO DO /30
passthru("$sshpass -p $srv_mkt_pwd ssh sagu-pro@$srv_mkt_ip \"/ip address print without-paging ; /ip address remove \\\"$ips\\\" \" ");

You see, the result of the ARP LIST, where de name of ARP match de $id_pessoa, the GREP write in a file, temp.

Ok, but, in the file, the line have a /r (i debug in mk console) then, the script send to mikrotik the variable:

22:28:52 script,info 66-Thiago-Cardoso-Pepe\r

Look the "/r" in the end.

Not work.

If you see in the script, i added a $ips=substr_replace($ipsx ,"",-2); to remove the last 2 caracters in the line, including the line-break (/r)

Now, all working, the mikrotik receive:
22:38:52 script,info 66-Thiago-Cardoso-Pepe

and all script runs ok.

Your reply was crucial to the solution of my problem.

THANKS DUDE !!!
 
User avatar
Chupaka
Forum Guru
Forum Guru
Posts: 8712
Joined: Mon Jun 19, 2006 11:15 pm
Location: Minsk, Belarus
Contact:

Re: Comma - Error in terminal send " "

Thu May 07, 2009 1:38 pm

glad to hear it =)