John Garretson
John Garretson

Reputation: 15

PHP Remote Sudo Script Execution

I want a PHP script to cause a shell script to execute on a remote server as root. The script needs to execute sudo commands itself so it needs to be executed as root.

Any Ideas?

I tried having PHP ssh login and execute with sudo but it was too slow.

(I have Ubuntu 10.04 & PHP5 on both servers)

Upvotes: 0

Views: 521

Answers (2)

MerlinTheMagic
MerlinTheMagic

Reputation: 605

I recently published a project that allows PHP to obtain and interact with a real Bash shell. Get it here: https://github.com/merlinthemagic/MTS

After downloading you would simply use the following code:

$shell    = \MTS\Factories::getDevices()->getLocalHost()->getShell('bash', true);
$return1  = $shell->exeCmd('yourFirstCommand');
$return2  = $shell->exeCmd('yourSecondCommand');
//the return will be a string containing the return of the script
echo $return1;
echo $return2;

Upvotes: 0

David van Laatum
David van Laatum

Reputation: 654

SSH shouldn't be to slow unless your running many individual commands. If it is slow either the systems are under high load or you have reverse DNS problems. You could try setting UseDNS no in /etc/ssh/sshd_config and restart sshd if that makes it faster DNS is the problem.

The script needs to execute sudo commands itself so it needs to be executed as root.

Doesn't make sense if the script is running as root it doesn't need to use sudo.

Upvotes: 2

Related Questions