Why my shell_exec() donot work.
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 |
I create a shell like this:
--- #!/bin/sh echo "hello" ------ then I executed it in php: echo shell_exec('/tmp/helpdesk/hy10.sh'); It works.but hy6 still does not work,I cannot find the reason. |
My guess is that the user that runs php (apache? nobody?) can't
"su - postgres" w/o a password... how do you enable verbose error messages in PHP? I'm not proficient in PHP, it's been ages that I last had to use it :} Cheers, Tink |
Tink,thanks your reply.
I try to execute like this, shell_exec("su - root -s /tmp/helpdesk/hy6.sh") In /var/log/message ,I can find that a session has been opened for root ,but then nothing has happened. I execute it like this shell_exec("su - root -s /bin/sh -c '/usr/local/pgsql/bin/pg_dump' 'helpdesk' > '/tmp/helpdesk/helpdesk.dump'" ." 2>&1"); the error is :standard in must be a tty. My linux`s user is root,password is webcharge.In postgre,I create an user,root,password is a there is realations between there? thanks a lot suqin |
All times are GMT -5. The time now is 07:47 PM. |