bobmct Posted October 18, 2011 Share Posted October 18, 2011 In my php web program I'm trying to execute a bash shell script on the web server passing to it some parameters gathered within the program. Ideally I wouldl ike to run this script as another user. However, I get only a return code of "1" and no other error messages that I can see. I tried using system and passthru as well and I'm sure the script is executable by anyone. I've also tried the sticky bit on the target shell script. Can someone/anyone please provide some gotcha pointers about doing this? As can be expected, after playing with this for a week now I'm extremely frustrated and nearly exhausted my resources (except for this forum). Ideas/suggestions please? Thanks Quote Link to comment https://forums.phpfreaks.com/topic/249336-executing-shell-script-using-exec/ Share on other sites More sharing options...
xyph Posted October 18, 2011 Share Posted October 18, 2011 What happens when you run this script: <?php exec( 'whoami', $return, $result ); print_r( $return ); ?> Quote Link to comment https://forums.phpfreaks.com/topic/249336-executing-shell-script-using-exec/#findComment-1280290 Share on other sites More sharing options...
bobmct Posted October 18, 2011 Author Share Posted October 18, 2011 The web server is running as user www-data and the script is owned by podcast:podcast with the permissions of rwsr-xr-x The target script is already in production run by cron and sometimes from the CLI. Hope this helps Quote Link to comment https://forums.phpfreaks.com/topic/249336-executing-shell-script-using-exec/#findComment-1280297 Share on other sites More sharing options...
xyph Posted October 18, 2011 Share Posted October 18, 2011 I'm trying to verify that PHP is properly executing external applications, thus my example. If the output of whoami is as expected, then it's a pathing or permission issue. Have you read the user comments about exec in the manual? There are a lot of 'gotcha's that require a little more knowledge about your setup than you've provided. Quote Link to comment https://forums.phpfreaks.com/topic/249336-executing-shell-script-using-exec/#findComment-1280300 Share on other sites More sharing options...
bobmct Posted October 18, 2011 Author Share Posted October 18, 2011 Thanks - I do believe its a permissions issue. I have read through all the comments under the referenced functions found in us.php.net but I will read them again. Perhaps I've missed something. I will post my result after I have an opportunity to reread those comments. Bob Quote Link to comment https://forums.phpfreaks.com/topic/249336-executing-shell-script-using-exec/#findComment-1280305 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.