1828406 Members
3562 Online
109977 Solutions
New Discussion

Script Required

 
SOLVED
Go to solution
M.sureshkumar
Regular Advisor

Script Required

Hi All,
We need script for % of cpu and free memory.
1.sar -uM 1 1
vvc1app2@root>sar -uM 2 2
HP-UX vvc1app2 B.11.11 U 9000/800 09/08/06

12:02:56 cpu %usr %sys %wio %idle
12:03:01 0 0 0 0 100
1 1 0 0 99
2 0 1 0 99
3 11 1 0 89
system 3 1 0 97
12:03:21 0 0 0 0 100
1 0 0 0 100
2 0 0 0 100
3 0 0 1 99
system 0 0 0 100

Average 0 1 1 1 98
Average 1 3 1 0 97
Average 2 0 1 1 98
Average 3 5 1 0 93
Average system 2 1 0 97

2.app2@root>vmstat
procs memory page faults cpu
r b w avm free re at pi po fr de sr in sy cs us sy id
1 0 0 188372 3379377 107 16 0 0 0 0 0 1057 1540 139 0 1 99

Requirement:
1.In sar -uM 5 5 command output ,the last line gives the aveage % idle for cpu i.e 97%.If we will subtract from 100%,it will give % of CPU used i.e 3%(100 -97 =3%).We need this output i.e % of CPU used, in single script .
2.In vmstat command ouput,the free memory is 3379377 KB.If we will multiply by 4, it will give free memory in KB,after that we will divide by 1024 it will give in MB and again divide by 1024 it will give in GB.We need out put in GB only in single script.

The above two requirement is required in single script.Pls give the script for the above requirement.

Regards,
Suresh.
3 REPLIES 3
RAC_1
Honored Contributor
Solution

Re: Script Required

sar -uM 1 4|grep 'Average system' | awk '{printf "%d %s\n",(100-$NF),"%"}'
vmstat 1 4|awk '{print $5}'|grep -v '[a-zA-Z]'|awk '{(s+=$1)} END {printf "%d %s\n",s*4096/1024,MB}'

Down and dirty though.
There is no substitute to HARDWORK
Peter Nikitka
Honored Contributor

Re: Script Required

Hi,

a modified/simplified version (note for printf:
%% -> %):

sar -uM 1 4 | awk '/Average system/ {printf("%d%%s\n",100-$NF)}'

vmstat | awk '/^ *[0-9]/ {printf("%dGB\n",$5/256/1024)}'

mfG Peter
The Universe is a pretty big place, it's bigger than anything anyone has ever dreamed of before. So if it's just us, seems like an awful waste of space, right? Jodie Foster in "Contact"
M.sureshkumar
Regular Advisor

Re: Script Required

Hi All,

Thank you for ur given input.

Regards,
Suresh.