1

So, i'm on my ubuntu server and want to execute the following command:

su -c /path/to/command -s /bin/bash -l otheruser

When i type this command in the linux command line, it perfectly asks for the password for the otheruser and executes the command.

However, when i do it like this

exec("su -c /path/to/command -s /bin/bash -l otheruser");

it doesn't do anything. I haven't of course specified a password for it yet, but it doesn't really return anything that could help me solve this problem. I have set the permissions to that command to 777 for testing purposes.

Any suggestions?

Beeelze
  • 503
  • 1
  • 9
  • 25

1 Answers1

5

Try this:

<?php

$ret = exec("su -c /path/to/command -s /bin/bash -l otheruser", $out, $err);

var_dump($ret);
var_dump($out);
var_dump($err);

?>

More Info: http://us3.php.net/manual/en/function.exec.php

Also, if you are expecting the exec command to ask you for the password for the other user (as it did in the linux command line) - it won't work, exec command isn't interactive. You'll need to pass the password on the command, inline.

Latheesan
  • 23,247
  • 32
  • 107
  • 201