Reputation: 21
Can somebody please help me to write a KSH Script to get the CPU usage of the AIX server ?
Here I want my script to get the Current usage of CPU that time it is executed
Upvotes: 0
Views: 4505
Reputation: 2543
There are a number of tools on AIX (and elsewhere) to get the current CPU usage.
sar -u 1 1
to get the current cpu usage. See the manual page of sar for a whole lot of options. Depending on your installation you need to be root or add your user to the group "adm".w -u
. It outputs a little bit more than you ask for. If you don't need that you can use awk/sed/cut to cut it away.Upvotes: 1
Reputation: 15300
I use the following script in bash, but I just tried it in ksh and it works all the same:
top -bn2 | grep 'Cpu(s)' | sed -n '2s/.*, *\([0-9.]*\)%* id.*/\1/p' | awk '{print "CPU: " 100 - $1" %"}
You can also use
top -bn1 | grep 'Cpu(s)' | sed -n 's/.*, *\([0-9.]*\)%* id.*/\1/p' | awk '{print "CPU: " 100 - $1" %"}'
for faster response, but the result will be less accurate.
Upvotes: 0