Top command

Hey,
Using one single line of command i am trying to show the CPU usage for 4 processors and then filter it out and write it to a text file. Everything seams ok except that i am not able to switch from having the top command show me all CPU processes seperate opposed to showing me the average of all 4.
I know once i go into top, i can toggle that option by hitting the '1' key. However, i would like to have one command that does this.

I've looked into different configurations files as well but no luck. Any ideas or help would be appreciated. Thanck You

Georges A A

EX:

top -n 1 | cat | head -6 | tail -3 | tr -cs 'a-z',.,'0-9' '\n' | sed '1,8d' | sed '2,8d' | sed '3,9d'> /output.txt

This commmand will get and filter the CPU process and write it to a text file. However, this is only displaying the average of all 4.

In case you have Solaris installation, you may use prstat

#Prints the cpu usage in sorted order

 prstat -s cpu  

#Prints top 10 processes and also provides the statistics per user

prstat -a -s cpu 

Thanks,
Nagarajan Ganesan.

Unfortunately Not, i'm using RedHat

What do you get when you replace "top -n 1" with just "top" ?

-n 1 will only produce one iteration.

I think this will work for you.

Use the echo command. here is an example.

echo | top -n 1

But keep in mind, the first iteration, similar to prstat and iostat, is usually junk data and not quite information until you hit the second iteration. But the above will do what you want.

Just as an fyi, it is also helpful in scripting, especially commands that wait for input like format and top and any of the xxstat commands.

echo | format

-S

i forgot a small piece of this.

To pump the output to file.

echo | top -n 1 > /tmp/somestats.txt

or

echo | format > /tmp/diskinfo.txt

to pump the output to file.

-S

tx for the suggestion, however it doesn't seam to work. I tried the following

echo | top -n 1
echo | top
echo 1 | top -n 1
echo 1 | top

all those produce the same error output "top: failed tty get"

Any ideas ?

i have never seen that error message before. No idea why it is happening. Try echo | format and see if that works. If it does, then there may be some other issue specific to running it with top on your system.

I have never had any problems echoing out top or other similar commands.

try the echo | format and see what happens.