executing shell script from php - how?
Moderator: General Moderators
executing shell script from php - how?
hi,
i am using shell_exec('pathtofile/myShellScript') to execute my shell script
but it fails to execute the script.
Any solution?
i am using shell_exec('pathtofile/myShellScript') to execute my shell script
but it fails to execute the script.
Any solution?
Re: executing shell script from php - how?
Do you get an error message?jito wrote:but it fails to execute the script.
If you do please post the error message.
Please also try
see also: http://unixhelp.ed.ac.uk/CGI/man-cgi?which
Code: Select all
<?php
$cmd = 'pathtofile/myShellScript';
echo 'is_file: ', is_file($cmd) ? 'true':'false', "<br />\n";
echo 'which: ', shell_exec('which '.$cmd);
$output = shell_exec($cmd);
echo htmlentities($output);
?>inside the shell script i ouput some values, and get tose values while running php script, so it's sure, the script is running without any problem. But the problem i think is with the shell script. I was trying to create a system user with the shell script.Normally i run that script and it worked, as i was the `root` user then, but when i'm trying to run that script using php it fails, as only root can create a user a/c. Is it clear?
Any help?
Any help?
Please tryand post the output.
If the output contains the dns name of your server and you don't want us to see it remove that part.
Code: Select all
<?php
$cmd = 'pathtofile/myShellScript';
echo 'sapi: ', php_sapi_name(), "<br />\n";
echo 'sapi: ', php_uname(), "<br />\n";
echo 'whoami: ', shell_exec('whoami'), "<br />\n";
echo 'is_file: ', is_file($cmd) ? 'true':'false', "<br />\n";
echo 'is_readable: ', is_readable($cmd) ? 'true':'false', "<br />\n";
echo 'is_executable: ', is_executable($cmd) ? 'true':'false', "<br />\n";
echo 'which: ', shell_exec('which '.$cmd.' 2>&1');
$output = shell_exec($cmd.' 2>&1');
echo htmlentities($output);
?>If the output contains the dns name of your server and you don't want us to see it remove that part.
sapi: apache2handler
sapi: *******************
whoami: apache
is_file: true
is_readable: true
is_executable: true
which: /usr/bin/newAcc.sh <H[JFile found The user id: hari Password is: ENujOT0S /usr/bin/newAcc.sh: line 51: //: is a directory Sorry, sudo >ust be setuid root. newusers: can't lock /etc/passwd. touch: creating `hari': Permission denied chown: `hari:mail': invalid user chmod: changing permissions of `hari': Operation not permitted /usr/bin/newAcc.sh: line 61: cd: /home/hari: No such file or directory touch: creating `.procmailrc': Permission denied chown: `hari:hari': invalid user /usr/bin/newAcc.sh: line 65: .procmailrc: Permission denied /usr/bin/newAcc.sh: line 66: .procmailrc: Permission denied /usr/bin/newA
sapi: *******************
whoami: apache
is_file: true
is_readable: true
is_executable: true
which: /usr/bin/newAcc.sh <H[JFile found The user id: hari Password is: ENujOT0S /usr/bin/newAcc.sh: line 51: //: is a directory Sorry, sudo >ust be setuid root. newusers: can't lock /etc/passwd. touch: creating `hari': Permission denied chown: `hari:mail': invalid user chmod: changing permissions of `hari': Operation not permitted /usr/bin/newAcc.sh: line 61: cd: /home/hari: No such file or directory touch: creating `.procmailrc': Permission denied chown: `hari:hari': invalid user /usr/bin/newAcc.sh: line 65: .procmailrc: Permission denied /usr/bin/newAcc.sh: line 66: .procmailrc: Permission denied /usr/bin/newA
You can use sudo to grant the "user" apache root permissions for /usr/bin/newAcc.sh
Do not forget to set the NOPASSWD flag, otherwise sudo will ask for the account's password and the php process hangs.
Do not forget to set the NOPASSWD flag, otherwise sudo will ask for the account's password and the php process hangs.