Log the result of "do shell script: to a file

How can I log the result of a shell script into a log file?

I want to log every hour the result of “top” command to a log file.

do shell script “date >> /test.log” – will log the date
do shell script “top”
set top_report to result
do shell script “echo top_report >> /test.log”

Something like this will log the date and on the next line will be top_report.
The log will read:
Thu Nov 18 13:32:27 EST 2004
top_report

What I’m looking for is
Thu Nov 18 13:32:27 EST 2004
Processes: 79 total, 3 running, 76 sleeping… 194 threads 13:33:12
Load Avg: 0.19, 0.23, 0.17 CPU usage: 84.0% user, 16.0% sys, 0.0% idle
SharedLibs: num = 120, resident = 36.6M code, 3.55M data, 9.59M LinkEdit
MemRegions: num = 9489, resident = 125M + 19.3M private, 160M shared
PhysMem: 90.9M wired, 237M active, 392M inactive, 720M used, 303M free
VM: 5.90G + 82.3M 71269(0) pageins, 4(0) pageouts

PID COMMAND %CPU TIME #TH #PRTS #MREGS RPRVT RSHRD RSIZE VSIZE
1310 top 7.0% 0:00.78 1 16 26 352K 464K 728K 27.1M

Can anybody help me with this (should be easy) script?

This should do the job:

top -l 5 >> log.txt

(will log only 5 samples)

Thanks jj!

Yes, it does!