Capture Top Command Output

bclancey

Verified User
Joined
May 19, 2004
Messages
39
As part of our trouble-shooting we needed to have a script which would capture output from the top command throughout the day.
After reviewing the man pages for top and searching the web, I found the following script:

Code:
#!/bin/sh
TERM=vt100
export TERM
date
top -b -n 1
exit 0
Running the above script generates output, which is emailed to you.

The following sh script can be run every minute from cron to allow you to track considerable data in the minutes leading up to a crash or server freeze. The data is saved to a logging directory, using the number for the minute as the file name. In my installation, this creates 60 files, which are refreshed with new data every 60 minutes.

Code:
#!/bin/sh
TERM=vt100
export TERM

time=$(date)
min=${time:14:2}

top -b -n 1 > /home/my-home/log/$min
netstat -an >> /home/my-home/log/$min
ps aux >> /home/my-home/log/$min
free >> /home/my-home/log/$min
exit 0
 
Last edited:
Back
Top