0

I have this command and it works fine on shell. I want to run it with php but it does not work what i missed :

edited :

$arg="arg1"; $arg2= "arg2";

echo shell_exec("sshpass -p ".escapeshellarg($arg)." ssh -t root@00.00.00.00 'asterisk -rx ".escapeshellarg($arg2)."'");

after this change no error on output but still commande not executed

edited : the original commande is like this :

sshpass -p 'arg1' ssh -t root@00.00.00.00 'asterisk -rx "arg2"'

and i want to around the probleme with external parameters but it does not work

Jozef
  • 1
  • 3
  • The problem that you're using single quote inside double qoutes to use functions. `echo shell_exec("sshpass -p ".escapeshellarg($arg)." ssh -t root@00.00.00.00 'asterisk -rx ".escapeshellarg($arg2)."'");` this will work. – Mohammed Alhanafi Nov 14 '19 at 01:44
  • it doesn't work :( – Jozef Nov 14 '19 at 08:34

2 Answers2

0

If the php is running on safe mode, it won't allow to execute shell_exec as it's described in the php manual:. https://www.php.net/manual/en/ini.sect.safe-mode.php

You can disabled the safe mode for a certain folder as it's described in the Stack Overflow question:

How to turn off php safe_mode off for a particular directory in a shared hosting environment?

Code Rage
  • 555
  • 3
  • 9
  • Can you edit the original post to replace the single quotes to double quotes as advised on the comment above and describe the output or which error do you receive. – Code Rage Nov 14 '19 at 10:20
0

Finally I found a good solution for who still search :

I installed php-ssh2 with this link (i use debian 8, php7)

blog.programster.org

and in my case i use codeigniter i follow the link to implement this class

bitbucket.org

now i can execute any commande on shell without probleme

and the probleme is solved :)

Hope its help someone :)

Jozef
  • 1
  • 3