On 18-Feb-02 Eric Sellin wrote:
Much easier to do a "tail -f" on the Web server's log file, read lines in a loop and do whatever we want to do for each line.
Assuming that's how you tell a page has been accessed, then this is a neat way of doing it.
BTW, I think it's time Jenny told in a bit more detail what she needs to do when the web-page is accessed. Is it any web-page, with a different action for each web page? Or is it the same action for any access? Is it simply access to the web-site as a whole?
In any case, following up on Eric's suggestion above, 'awk' would be a very good way of doing it, since it is designed to be a program which automatically responds line-by-line to line-by-line input. This would go on the following lines:
tail -f -l 1 access_log | awk 'BEGIN{next} {system("cat append_file >> other-file")}'
'tail' tracks access_log, outputting the most recent line added to it. The BEGIN action discards the stale initial line which would be read from access_log on startup. Thereafter, each new line output by tail will trigger the append.
However, this assumes that a web-page access appends one line only to access_log. and would fail if a web-page access generated several lines in access_log, since then each of these would trigger the append. In that case one would need to make the 'awk' command a bit more intelligent.
For instance, suppose -- no matter how many lines a single web-page access generated -- there was amongst these a single line containing a certain pattern. Then you can make 'awk' respond only to lines containing this pattern, as in
tail -f -l 1 access_log | awk 'BEGIN{next} /pattern/{system("cat append_file >> other-file")}'
Since (in the 'awk' command) /pattern/ can be a regular expression, this also allows several different (but equivalent) forms of pattern to be recognised as indicating that a web-page has been accessed; and, should a different action be required for some, this can also be accomodated; as in:
tail -f -l 1 access_log | awk 'BEGIN{next} /pattern1/{system("action 1")} /pattern2/{system("action 2")} .... /patternN/{system("action N")}'
And so it goes ... Ted.
-------------------------------------------------------------------- E-Mail: (Ted Harding) Ted.Harding@nessie.mcc.ac.uk Fax-to-email: +44 (0)870 167 1972 Date: 18-Feb-02 Time: 15:46:48 ------------------------------ XFMail ------------------------------