Page 1 of 1
executing shell script from php - how?
Posted: Wed May 02, 2007 8:33 am
by jito
hi,
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?
Posted: Wed May 02, 2007 8:39 am
by volka
jito wrote:but it fails to execute the script.
Do you get an error message?
If you do please post the error message.
Posted: Wed May 02, 2007 8:40 am
by feyd
Are you sure the path is correct? Are you sure the script is executable by php's user? Have you tried the other execution functions such as
system()?
Posted: Wed May 02, 2007 8:43 am
by jito
100% sure the path is correct, even tried with the absolute path. i have tried passthru, exec other than shell_exec, but that also fails. And i'm getting no error message. Just going to check with system().
Posted: Wed May 02, 2007 9:11 am
by volka
Please also try
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);
?>
see also:
http://unixhelp.ed.ac.uk/CGI/man-cgi?which
Posted: Wed May 02, 2007 9:17 am
by jito
thank you volka, i already tried that. But i think problem is elsewhere. Actually i'm trying to create a new syatem user with the user and password generated from a php script. i think the problem is with the permission to craete user.
Posted: Wed May 02, 2007 9:45 am
by volka
What did it print?
Posted: Wed May 02, 2007 10:03 am
by jito
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?
Posted: Wed May 02, 2007 10:55 am
by volka
Please try
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);
?>
and 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.
Posted: Wed May 02, 2007 11:25 am
by jito
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
Posted: Wed May 02, 2007 12:07 pm
by volka
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.