[Solved] Getting the CPU utilization in a file periodically

Hi,

I am trying to create a script that will run for every 5 mins to grep the CPU utilization. I have 6 instances running on a single unix server for which I have to export the individual utilizations periodically.
Can we fetch the utilization of 6 instances in separate files using top command? Or is there any other command that I should use?
I tried writing the below line of code

top -b -d1 -n1|grep "CPU" |grep -i "instance name"|head -c21|cut -d ' ' -f3|cut -d '%' -f1 >> file1.csv

top -b does not seem to work.

I am using #! /bin/sh

What do you mean by "top -b does not seem to work"? What OS are you on? What happens when you invoke "top -b"? It should run until you kill it.

depends which os you are using for top...

type

which top 

send us the output.

top does not exist on aix if that is what you are using.

Hello Techy1,

Could you please try following command in AIX it should work.

topas
 

Please press q to come out of it.

Thanks,
R. Singh

lol i think that was directed to the OP not me. and were not sure of the OS the OP is using since topas is a aix utility.

Hi,

The output to

which top 

is :

 
$ which top
/usr/bin/top
 
$ top -b
top: illegal option -- b
Usage:  top [-u] [-w] [-q] [-P] [-dx] [-sx] [-p pset_id] [-n number] [-f filename]

Our OS is HP_UX.

There is no batch mode in HP-UX... it offers you the possibility to output to a file using -f filename so

top -f mytop.out 

would give you the output of 1 iteration and 16 process by default (-d1 -n16...)

That said ever considered using ps with UNIX95 option?
look at the output of for CPU:

UNIX95=1 /usr/bin/ps -e -o pcpu,args | /bin/sort -u -r | sed -e 's/\.[0-9][0-9]/&\%/g' | sed -n 2,6p

...

It works perfectly. Thanks all!!!!