View Full Version : Display output from Unix shell script as it happens

05-10-2004, 04:47 AM

I am trying to write an interface using php that will allow users to execute various shell scripts on our Unix server from a single internal web page.

Is there any way to have the output from these scripts print to my page as it happens. Some scripts can take up to 1/2 an hour to run, so it is not really ideal to wait until they finish processing, then display the output in one hit.

Ideally I would have a text box that keeps updating it's contents periodically until the script finishes.


05-10-2004, 07:50 PM
you can use output buffering , though you may need to actually open a pipe and talk to it , look in the manual for ob_start & ob_end_flush + proc_open & proc_close (good example in proc_open)

but the reason I posted was to say that your idea is an incredibly bad one , however safe you try to make it, to be usable/useful it has to be unsafe ! , if your users need the shell then why not look at SSH etc ?

05-11-2004, 12:16 AM
Thanks for the reply,

This page is only available from within our Domain and I was planning on using a single secure directory to store all the runnable scripts.

Any physical output (.csv files etc) will be available for download via a link, and avaliable to specified users only.

It would just be nice to be able to let the user see the progress messages from the shell scripts while they wait.

Do you think ssh might be more than I need?
I can live without the output until the end of a system() call if it is going to open up unnecessary risks.

05-11-2004, 03:07 AM
Hi , sorry but I think I got the wrong end of the stick :o , I thought you were allowing users to pass shell commands via the browser to be executed by exec() etc , I see now that you mean you have some existing pre-written shell scripts that you simply want a browser interface to run, in which case the nonsense above is exactly that !

ok how to check the progress of the scripts.. do the scripts have any output while running ? in which case the example at http://www.php.net/proc_open may be useful as you can read the output & flush() to the browser , if not (and I see the script creates other files) you can check the size of those files periodically , that usually means 2 scripts though , 1 to spawn the system call & the other to track the status of the created file, so you would have to say $pp=popen('/usr/blah/scripts/blah.sh','r'); the shell script then check the filesize of the created files and keep flush()ing

If I can think of a better example I will

05-11-2004, 03:15 AM
Sweet, that proc_open looks like the business.
The output I want to display is from echo statements within the shell scripts, so should be fairly straightforward after looking at that link you provided.

Thanks a lot for the help :)