Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It's 100% free, no registration required.

Firstly, any advice on improving the title appreciated!

I want a webpage to reflect a log file. I have a bash script that converts the log to html. Currently this runs periodically via crontab, which works, but obviously executions are redundant when the webpage isn't viewed. I'd like to implement a system so the bash script runs only called when the webpage is called.

I gather an index.php script along the lines:

<?php
$message=shell_exec(". /path/script.sh");
?>

.. should generate the index.html file ok. But is there an easy way to get index.php/Apache to serve that file to the client browser? Advice much appreciated.

share|improve this question
1  
Why not use [a modified version of] your bash script as a CGI instead of a PHP proxy? –  Nasha Apr 30 at 16:25

3 Answers 3

Another option:

Create an .htaccess file in your web server root with the following:

AddType application/x-httpd-php .htm .html

Now apache will process .htm and .html files as php documents and any <?php ... ?> tags located in that file will be interpreted as php.

share|improve this answer

I gather the best solution is to end the php with:

header('Location: index.html');
exit;
share|improve this answer

I suppose you could use readfile to dump the file you've just created towards the browser. Alternatively, you could issue a 302 temporary redirect to index.html.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.