使用php执行shell脚本
作者:互联网
我有一个shell脚本deploy.sh,它包含以下内容: –
echo "0 Importing the code"
eval "git pull -u origin master"
echo "1 Backing up existing data in database.."
// -- other code follows here
当我使用终端直接执行脚本时,我得到以下输出: –
0 Importing the code
remote: Counting objects: 5, done. remote: Compressing objects: 100% (2/2), done. remote: Total 3 (delta 1), reused 0 (delta 0) Unpacking objects: 100% (3/3), done. From bitbucket.org:user/repo * branch master -> FETCH_HEAD Updating db13xxx..6705xxx
1 Backing up existing data in database..
这是对的.但是,我编写了一个PHP脚本,我可以通过http来调用deploy.sh脚本.这个php页面的内容如下: –
$output = `./deploy.sh`;
echo '<pre>', $output, '</pre>';
当我通过浏览器调用这个php文件时,shell脚本实际上被调用了,我得到以下输出: –
0 Importing the code 1 Backing up existing data in database..
问题是eval“git pull -u origin master”命令没有执行,它的输出也没有显示.知道问题是什么吗?
解决方法:
这有效
<?php
$output = shell_exec('sh deploy.sh');
echo "$output";
?>
在此之前,请确保该文件具有chmod 777权限.
标签:shell-exec,php,shell 来源: https://codeday.me/bug/20190725/1535489.html