Hi Jenny,
On 18-Feb-02 Jenny_Hopkins@toby-churchill.com wrote:
Can anyone help me with a bit of php? I need to append the copntents of one file on to another when a web page is accessed. Cron is no use as the timing isn't fixed. I can append a line of text so far, but not the contents of a file, and as I'm away for the rest of the week and have been doing this manually till I find the fix, I'm panicking!
- help!
Cheers, Jenny.
1. One way to do something in Linux/Unix when something else happens is to run a little script in the background which watches for the event and then takes action. The logic is:
while true ; do if <test for occurrence of event> ; then <do action> fi sleep <some seconds> done
This, every <some seconds>, checks whether the event has occurred and, if it has, takes action.
2. To append one file to another, do
cat appended_file >> other_file
3. I don't know how one "registers" an access to a web page within Linux. Suppose, however, that the access updates some file called "acces_log". Then the script in (1) could be
touch watch_access_log while true ; do if [ access_log -nt watch_access_log ] ; then cat appended_file >> other_file fi sleep 10 touch watch_access_log done
This works by (a) updating the time-stamp on watch_access_log at startup (creating it if it doesn't exist); (b) going into an infinite loop; every time round, it checks whether access_log's time-stamp is newer than ("-nt") watch_access_log's time-stamp (which will happen if access_log has been changed since last time the file watch_access_log was touched); if so, then (c) it does the append; (d) then, in any case, it touches watch_access_log so that its time-stamp carries the latest time the loop was run, waits 10 seconds, then re-runs the loop.
Suppose the script is called "watch_web_page". Then you start it up with
watch_web_page &
Hope this gives you some useful ideas, even if it isn't exactly what's needed! Ted.
-------------------------------------------------------------------- E-Mail: (Ted Harding) Ted.Harding@nessie.mcc.ac.uk Fax-to-email: +44 (0)870 167 1972 Date: 18-Feb-02 Time: 13:51:07 ------------------------------ XFMail ------------------------------