Link to home
Start Free TrialLog in
Avatar of gxp071
gxp071Flag for United Kingdom of Great Britain and Northern Ireland

asked on

execute bash script from php

Hi Im trying to execute a simple bash script from php that does an svn update, the bash script works from the command line and I have chmod'd the file to 777  i need help getting it to execute from php.  I have adapted this script from the php docs but i cant get it to work,

Any help would be greatly appreciated.

Thanks
<?php
 
echo '<pre>';
 
// Outputs all the result of shellcommand "ls", and returns
// the last output line into $last_line. Stores the return value
// of the shell command in $retval.
$last_line = system('bash /home/xxxxxxxxxxxxx/svn-up', $retval);
 
// Printing additional info
echo '
</pre>
<hr />Last line of the output: ' . $last_line . '
<hr />Return value: ' . $retval;
 
?>

Open in new window

Avatar of wildzero
wildzero

Hey there

I think you just need to change this
$last_line = system('bash /home/xxxxxxxxxxxxx/svn-up', $retval);

to
$last_line = system('/home/xxxxxxxxxxxxx/svn-up', $retval);

then as long as you have
!#/bin/bash
or line the same (path to bash) at the top of your bash script you should be sweet.

This is the php command i use to export a copy of our reposatory.

<?php
... some stuff..

$result = shell_exec('svn export svn://192.168.1.221/proj1/trunk website/ --force');
$result = trim($result);
echo $result;
?>

Also, there is svns's hooks that you can use
Example is the post-comit hook which runs each time you comit a file to the reposatory... it might be worth looking at those depending on what your doing, just go a search in google for svn hooks

:-)
Hi,

Your script would seem correct. Things you can try are defining the entire path to the bash executable, just in case PHP's using a strange path, adding "2>&1" to your command (as in system('bash /home/xxxxxxxxxxxxx/svn-up 2>&1', $retval);) in order to get the potential messages otherwise going to stderr and trying a different approach in PHP entirely. Things to try would be the exec() command and the `command` approach (note the correct character, ` is not '), i.e.

echo "This system is " . `uname -a`;
Avatar of gxp071

ASKER

Hi,  first of all thanks for helping.

I should of mentioned I had already tried the command without the 'bash ' part, to no avail,  I have attached the bash script as you can see dead simple I have blanked out the paths.  


#!/bin/bash
 
cd /home/xxxxxx/public_html/..../..../....../
svn up
cd /home/xxxxx/public_html/..../....../.../...../....../.../
svn up

Open in new window

It could still be a path issue, in the bash script the command "svn" isn't referenced by full path. Why don't you exec the commands now in the bash script directly from PHP? This way you coud get individual error handling.
Avatar of gxp071

ASKER

i added 2<&1 showed the error message,

svn: Can't open file '.svn/lock': Permission denied

I'm guessing that my apache user does not have permission to use, modify the svn control files.

i Have also just tired

$result = shell_exec('svn update /home/xxxxxx/public_html/......./....../....../.../..../');
$result = trim($result);
echo $result;

and I get: skipped '.'

the same command from shell works correctly.

background on what i'm trying to do its provide a method for designers to push there changes to a dev server without having to ssh in and svn update every time they commit there working copy to the repository.
ASKER CERTIFIED SOLUTION
Avatar of absx
absx
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of gxp071

ASKER

Hay guys thanks, for all your help, ive split the points 50/50 as you both been great help.