LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 04-07-2005, 12:11 PM   #1
farmerjoe
Member
 
Registered: Oct 2004
Location: Texas
Distribution: Ubuntu - Home, RHEL4 - Server
Posts: 96

Rep: Reputation: 15
How do I display real shell script output to web page.


I have a shell script I wrote that downloads a specified file and also gets information about the file. Currently i am calling this script using this PHP function. However it displays all of the output all at once when the shell script has finished running.

$output = shell_exec($command);
echo "$output";

My problem is that some of these files are 100mb or more and i would like to display the progress of the script in real time to the webpage. I know PHP is server side and it is difficult to do this, but is there a way? If not in PHP, what about perl? I've seen shell scripts displayed in real time to web pages before, I just have no idea how its done. Any help would be greatly appreciated.


PS. Heres something I tried in PHP, but it is horribly inefficient and causes wiked load spikes due to the infinite loop. But maybe something like this would work with some tweaking? However there must be an easier way to do it.



PHP Code:
<?php

/*
In order for this script to work, you must atleast chmod 404 the file .. it needs
to be world readable ... if not, this script will NOT work!
*/

ini_set("max_execution_time",0);
$filename "/var/log/maillog";

$file_size filesize($filename);

$fh fopen($filename'r');
$myOutput fread($fh$file_size);
$myOutput str_replace("\n""<br>\n"$myOutput);
#print $myOutput;
$c 1;
while ( 
$c == )
{
clearstatcache();
$tmpSize filesize($filename);
if ( 
$tmpSize <> $file_size )
{
$readBytes $tmpSize $file_size;
$file_size $tmpSize;
$myOutput fread($fh$readBytes);
print 
$myOutput;
echo 
str_pad(" "256) . "<br>";
flush();
$c=1;
}
}
?>
 
Old 04-07-2005, 01:03 PM   #2
farmerjoe
Member
 
Registered: Oct 2004
Location: Texas
Distribution: Ubuntu - Home, RHEL4 - Server
Posts: 96

Original Poster
Rep: Reputation: 15
Would the passthru(); function in PHP work for this? I have tried it and it didnt seem to work, but i could be using it wrong.

-farmerjoe
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
series-Write a single shell command to display the following output ricki Programming 2 07-31-2005 03:53 PM
Display a text file from hard drive into a web page EgosZ Linux - Networking 6 04-04-2005 10:51 PM
How do I make PHP display output from my shell script? farmerjoe Programming 2 04-03-2005 01:15 PM
shell script output redirection goral.j Programming 3 01-27-2005 05:34 AM
Kicking off a script form a web page Hazzie Programming 2 04-26-2004 01:09 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 01:33 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration