我有一组 bash 和 Perl 脚本
- 开发在 Linux Box 上部署所需的目录结构
-
(可选)从svn导出代码
- 从这个源构建一个包
这在终端上运行良好。现在,我的客户请求此流程的 Web 界面。
例如,某些页面上的“创建新包”按钮将一一调用上述步骤,并将输出作为脚本回显返回给用户,而不是在整个脚本执行时。
是否可以将 bash 脚本的即时输出发送到通过程序执行函数(系统、exec、passthru ...或任何其他适合此流程的东西)调用它的网页或 php 脚本?
优雅为何要这么做?
进行此类操作时我应该采取哪些安全预防措施(如果可能)?
Edit经过一番搜索,我找到了部分解决方案,但仍然不起作用:
$cmd = 'cat ./password.txt|sudo -S ./setup.sh ';
$descriptorspec = array(
0 => array("pipe", "r"), // stdin is a pipe that the child will read from
1 => array("pipe", "w"), // stdout is a pipe that the child will write to
2 => array("pipe", "w") // stderr is a pipe that the child will read from
);
flush();
$process = proc_open($cmd, $descriptorspec, $pipes, './', array());
echo "<pre>";
if (is_resource($process)) {
while ($s = fgets($pipes[1])) {
print "Message:".$s;
flush();
}
while ($s = fgets($pipes[2])) {
print "Error:".$s;
flush();
}
}
echo "</pre>";
output:(网页)
Error:WARNING: Improper use of the sudo command could lead to data loss
Error:or the deletion of important system files. Please double-check your
Error:typing when using sudo. Type "man sudo" for more information.
Error:
Error:To proceed, enter your password, or type Ctrl-C to abort.
Error:
Error:Password:
Error:Sorry, try again.
Error:Password:
Error:Sorry, try again.
Error:Password:
Error:Sorry, try again.
Error:sudo: 3 incorrect password attempts**
我现在遇到的第一个问题是传递 sudo 密码
请帮助 !