0

I want to run this code from php

echo <password> | sudo -S /usr/sbin/asterisk -rx "dongle show devices"

but it's not working. Can anyone help?

  • is your php_user(apache?) in the sudo-ers file? – corn3lius Dec 06 '13 at 04:04
  • http://stackoverflow.com/questions/3166123/how-to-call-shell-script-from-php-that-requires-sudo http://en.wikipedia.org/wiki/Setuid before posting you may search all over the possible ways – gvgvgvijayan Dec 06 '13 at 04:40

3 Answers3

0

You can just use the 'backtick' character (`) around your shell string like:

<?php
    $output = `command_goes_here`;
    echo $output;
?>

Keep in mind this will only work if the shell_exec() function would work on that server, which could also be used in a similar way.

0

Use php function shell_exec or exec to execute shell commands

For more details

http://www.php.net/shell_exec

http://php.net/manual/en/function.exec.php

Community
  • 1
  • 1
shakthydoss
  • 2,551
  • 6
  • 27
  • 36
0

u can try by this if u want to run shell script command in php file

$output = shell_exec('ls -lart');
echo "<pre>$output</pre>";

u can also try other way by create .sh file for shell script and run that .sh file by php function

$output = shell_exec('./deploy.sh');
echo "<pre>".$output."</pre>";
Mayur Kukadiya
  • 994
  • 6
  • 20