LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 09-10-2007, 02:00 AM   #1
bhwhy
LQ Newbie
 
Registered: Sep 2007
Posts: 4

Rep: Reputation: 0
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
 
Old 09-10-2007, 03:49 AM   #2
bhwhy
LQ Newbie
 
Registered: Sep 2007
Posts: 4

Original Poster
Rep: Reputation: 0
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.
 
Old 09-10-2007, 07:38 PM   #3
Tinkster
Moderator
 
Registered: Apr 2002
Location: earth
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928
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
 
Old 09-11-2007, 05:48 AM   #4
bhwhy
LQ Newbie
 
Registered: Sep 2007
Posts: 4

Original Poster
Rep: Reputation: 0
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
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
help with shell_exec MaX-PaYnE Linux - General 1 02-10-2007 05:40 AM
using shell_exec to restart apache? fuelinjection Linux - General 1 07-08-2004 12:24 PM
Xine donot starts ras123 Linux - Software 1 02-22-2004 01:05 PM
nmap and traceroute donot work rsnfunky Linux - Security 3 11-17-2003 09:59 AM
Why Samba donot know my files have been modified? whepin Linux - General 1 01-17-2002 08:03 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 10:12 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration