LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 11-30-2005, 05:27 AM   #1
Thin
LQ Newbie
 
Registered: Jul 2004
Location: Southern England
Distribution: Mandriva / Gentoo / CentOS
Posts: 27

Rep: Reputation: 15
Calling shell scripts from PHP as other users


Hi all

Quick question regarding permissions under Linux. I want to call a shell script from a php page that will start an application on the machine.

To test this out, I've had a go executing 'uptime' from a php page and the results are returned to the browser, minus the number of users logged in.

I've had a read around and am still a little confused as to how this works with Linux file permissions. Presumeably if the Apache user has execute access to the script, it will run, but if the script itself fires off other applications do these also need to be executable by the Apache user?

Really after a little thought what I want to be able to do is to call a script to be executed as another user (NOT root but not www/apache either) from a php page. I think this is acceptable as the script in question takes no user input, it merely executes.

Can anyone walk me through the best way to do this ? I've had a read around and initally thought suExec might be what I was looking for, but the tutorial didn't really help with this particular problem.

TIA

Last edited by Thin; 11-30-2005 at 05:29 AM.
 
Old 12-02-2005, 08:17 AM   #2
graemef
Senior Member
 
Registered: Nov 2005
Location: Hanoi
Distribution: Fedora 13, Ubuntu 10.04
Posts: 2,379

Rep: Reputation: 148Reputation: 148
I would guess that you want to use the php exec() function and then issue the sudo linux command with -u and -S switches

So the Linux command may be something like:
Code:
sudo -u myuser -S
So I suspect that the php code may be something like:

Code:
<?php
exec('sudo -u myuser -S');
exec('myuser_password');
exec('my_command'.escapeshellarg($args);
?>
This hasn't been tested so please take it slowly and please tell how you actually fixed it,

cheers,

graeme.
 
  


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
Calling For Paraguayan Users Ciccio Linux User Groups (LUG) 7 10-04-2006 05:46 PM
PHP and Shell scripts haze Programming 4 04-15-2005 02:52 AM
Allright, where is it? Calling Slack users! ONEderer Slackware 12 05-06-2004 08:13 AM
Calling Mac users c0rk3y Linux - Distributions 0 07-01-2002 02:46 PM
calling all BSD users.... theneoprotocol Linux - General 1 04-12-2002 06:37 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 12:49 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