I have a set of bash and perl scripts for
- create the directory structure needed for deployment in linux box
- (optional) export code from svn
- create package from this source
This works well with the terminal. Now my client is requesting a web interface for this process.
for example, the “Create a new package” button on a specific page is called up one after another above the steps and returns the result to the user as a script echos, and not when all scripts are executed.
Is it possible to send instant output from a bash script to a web page or a PHP script that called it through the program's execution functions (system, exec, passthru ... or something else that corresponds to this process thread)?
What is elegant, why do this?
What precautions should I take when doing such a thing (if possible)?
Edit After some searching, I found part of the solution, but still did not work:
$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: (web page)
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**
The first release I have now is to pass sudo passoword
help me please!