Hi.
I am new man to php.I want to execute a shell script using php on a linux,
but I failed.
I found some useful resource in this site,and then tested,but the question has not been soluted.
vj123 met the the same question as me,there is not a clear answer on this page.
http://www.linuxquestions.org/questi...ec#post2114059
slam said he has soluted the similar question,I tried to test on his mehtod
but still didnot success.
http://www.linuxquestions.org/questi...ec#post2114059
I tied the to execute the following code:
<?php
$cmd='/root/hy6.sh' ;
$output = shell_exec($cmd);
echo "<pre>$output</pre>";
?>
-------hy6.sh--------
#!/bin/sh
su - postgres -c "'/usr/local/pgsql/bin/pg_dump' 'helpdesk'> '/tmp/helpdesk/helpdeskback.dump'"
---------
I directly execute it like this : sh /root/hy6.sh
It works,but when I execute it in php,there is not any response.
If I execute like this:
shell_exec("su - postgres -c '/usr/local/pgsql/bin/pg_dump' 'helpdesk' > '/tmp/helpdesk/helpdesk.dump'");
there will be create a new file in the folder(/tmp/helpdesk/),but It has
0 bytes.
If I execute like this:
shell_exec("su - postgres -c \"'/usr/local/pgsql/bin/pg_dump' 'helpdesk' > '/tmp/helpdesk/helpdesk.dump'\"");
It doesnot work.Because I am not good at linux,so I want your help.
Any advice is appreciate,
Suqin