If you use https instead of ssh, you can specify the user / password directly in the request:
git clone:
exec("git clone https://user: password@bitbucket.org /user/repo.git");
git pull:
exec("git pull https://user: password@bitbucket.org /user/repo.git master");
Alternatives to disclosing your password:
- Use ssh key without password in the target system.
- Use client side certificates for https.
Update: if you need to get the output of the exec command for debugging or checking things, you can pass an array argument to it and then output it using standard iterative methods to the location of your choice. Here is an example that just prints the output:
function execPrint($command) { $result = array(); exec($command, $result); foreach ($result as $line) { print($line . "\n"); } }
Since the $result array will be added rather than overwritten by exec() , you can also use a single array to log the execution of the results of the exec commands.
source share