1829648 Members
9221 Online
109992 Solutions
New Discussion

Re: Top utility

 
Rahul_13
Advisor

Top utility

Hi,

I want to write a script that would execute 'top' in the background for 1 hour time and collect the reports in a file.

Can anyone please help me.

Thanks,
Rahul
3 REPLIES 3
Jared Middleton
Frequent Advisor

Re: Top utility

Rahul,

Have you reviewed the man pages for top?
$ man top

Depending on the version of top you're using, you might have -b and -n options.
My version of top...
$ top -v
top (procps version 2.0.7)

..has these options:

n Number of iterations. Update the display this number
of times and then exit.

b Batch mode. Useful for sending output from top to
other programs or to a file. In this mode, top will
not accept command line input. It runs until it pro-
duces the number of iterations requested with the n
option or until killed. Output is plain text suitable
for display on a dumb terminal.

By default top refreshes every 5 seconds, so if you have the above options, you might simply run:
$ top -b -n 720 > filename &

-Jared
ramkumar
Valued Contributor

Re: Top utility

hi


# nohup top -d 30 -n 200 -s >/tmp/temptop.out

where -d indicates time interval betwwen each top command
-n indicates number of top outputs


good luck

ram
Muthukumar_5
Honored Contributor

Re: Top utility

We can run top based on time delay and count. If you run continuously, there might not be more changes. You can use delay of five secs there.

So that,
------------------------------
#!/bin/sh
# top script
# top.sh
time=0
count=1
hour=${1:-1}
sleep=${2:-5}

while [[ $time -le $(($hour*3600)) ]]
do

# Secure mode and run 1 count
top -s -n 1 >> /tmp/topinfo.$count
sleep 5
let count=count+1
let time=time+5

done

# exit
exit 0
--------------------
Run this script as,

sh top.sh 1 5 &
so that it will run in background

and exit after 1 hour

You can collect data informations there at /tmp/topinfo.* files there.

Easy to suggest when don't know about the problem!