bash脚本执行从php和瞬时输出回到网页
我有一个bash和Perl脚本的集合
>开发在linux机器上部署所需的目录结构 这在终端上运行良好.现在我的客户端请求此过程的Web界面. 例如,某个页面上的“Create New Package”按钮将逐个调用上述步骤,并将输出作为脚本回声返回给用户,而不是在整个脚本执行时. 是否有可能将bash脚本的瞬时输出发送到网页或php脚本,该脚本通过程序执行功能(system,exec,passthru ……或任何其他适合此流程的东西)调用它? 什么是优雅为什么这样做? 在做这样的事情时我应该采取哪些安全预防措施(如果可能的话)? 编辑 $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>"; 输出:(网页) 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:sudo: 3 incorrect password attempts** 我现在要做的第一个问题是通过sudo passoword 请帮忙 ! 解决方法
我会使用一种主/从设计.奴隶将是你的perl / bash脚本,只是做一份工作(打包,编译,导出代码等),并提供一个日志条目.
主人将是你的PHP进程.因此原理如下:主设备和从设备共享通信信道,并从该信道异步通信. 您可以想象一个数据库,如: create table tasks ( id INT primary key,status INT,argument VARCHAR(100)); 你的php页面应该切换用户选择,并过滤输入: switch ($_GET['action']) { case 'export': $argument = sanitize($_GET['arg']); add_task('export',$argument); break; case '...': // ... } add_task函数可能是这样的: function add_task($action,$arg) { return $db->add('tasks',array($action,NEW_TASK,$arg); } 奴隶可以通过cron job运行,并查询数据库,提供任务的进展. 专业人士是: >独立系统,缓解进化. 缺点是: >一开始有点复杂. 请注意,您可以实现xml-rpc之类的触发器来运行从属服务器,而不是使用消息传递系统. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |