Operating System - HP-UX
1828349 Members
2948 Online
109976 Solutions
New Discussion

Re: Memory utilization of HP Unix server assign to a variable

 
Nair1980
Frequent Advisor

Memory utilization of HP Unix server assign to a variable

Hi All

I want to know how I can get the value of physical memory utilization in HP UNIX.

Even though I know many ways to get it, I am not able to call any of those methods from a script.

I want to know how I can get memory utilization value assigned to a variable from a script ???

Thanks in advance
Nair
10 REPLIES 10
AwadheshPandey
Honored Contributor

Re: Memory utilization of HP Unix server assign to a variable

MEM=`swapinfo|grep mem|awk '{print $3}'`
echo $MEM
It's kind of fun to do the impossible
Yogeeraj_1
Honored Contributor

Re: Memory utilization of HP Unix server assign to a variable

hi Nair,

you can also try:

echo phys_mem_pages/D | adb -k /stand/vmunix /dev/mem | tail -1 | awk '{printf("%.2f MB\n",$2*.004096)}'

or

mymem=$(echo phys_mem_pages/D | adb -k /stand/vmunix /dev/mem | tail -1 | awk '{printf("%.2f \n",$2*.004096)}')


e.g.

# mymem=$(echo phys_mem_pages/D | adb -k /stand/vmunix /dev/mem | tail -1 | awk '{printf("%.2f \n",$2*.004096)}')
# echo $mymem
7516.19


hope this helps too!

kind regards
yogeeraj
No person was ever honoured for what he received. Honour has been the reward for what he gave (clavin coolidge)
Hein van den Heuvel
Honored Contributor

Re: Memory utilization of HP Unix server assign to a variable

Nair, it would help to know which way you intend to get the memory to know the best solution. If it is a homegrown program then a call to 'putenv' is appropriate.

To put the output of any command in a shell variable just use the old backticks are Awadhesh suggests, but the $() method Yogeeraj uses is now preferred.
Other example:
$ FREE=$(vmstat | awk '/[0..9]/ { print $5 / 256 }')
$ print $FREE
11721.5

[The division by 256 converts 4096 byte pages to megabytes (1024*1024 bytes) ]



When interested in memory usage, be sure to check out:

ftp://hprc.external.hp.com/memory.htm#Monitoring_Memory_Usage

Specifically, it suggests that the 'mem' line Awadhesh picks up is actually psuedo memory and not ready for immediate consumption/interpretation.

Awadhesh....
>> MEM=`swapinfo|grep mem|awk '{print $3}'`
echo $MEM
Lots of nits to pick... Sorry...
) swapinfo is not int he path for ordinary users
) why feed into grep, when awk can compare
) some joker sa might have named a swap device with the string 'mem' in there. Really should anchor searched as a habit.
It makes them safer and faster.
) The data returned is of debatable use.

suggested alternative (if useful at all!)

MEM=$(/usr/sbin/swapinfo| awk '/^mem/{print $3}')

Cheers!
Hein.



Geoff Wild
Honored Contributor

Re: Memory utilization of HP Unix server assign to a variable

MEM=`echo "selclass qualifier memory;info;wait;infolog" | cstm | grep 'Total Configured' |head -1|awk '{print $5}'`


Rgds...Geoff
Proverbs 3:5,6 Trust in the Lord with all your heart and lean not on your own understanding; in all your ways acknowledge him, and he will make all your paths straight.
Hein van den Heuvel
Honored Contributor

Re: Memory utilization of HP Unix server assign to a variable

Hi (again) Geoff,

That's a big, SLOW, hammer you show!

But isn't that column $4, not $5 for the number?

btw... similar comments as I had for Awadhesh.

It's not going to make a difference here, but in general... why feed into different processes work which awk will happily do itself? Be explicit about some paths?


$ total=$( echo "selclass qualifier memory;info;wait;infolog" | /usr/sbin/cstm | awk '/Total Configured/{print $4; exit}' )
$ print $total
16384

Cheers,
Hein.
Geoff Wild
Honored Contributor

Re: Memory utilization of HP Unix server assign to a variable

Interesting:

# total=$( echo "selclass qualifier memory;info;wait;infolog" | /usr/sbin/cstm | awk '/Total Configured/{print $4; exit}' )

# echo $total
:

# total=$( echo "selclass qualifier memory;info;wait;infolog" | /usr/sbin/cstm | awk '/Total Configured/{print $5; exit}' )

# echo $total
16384

The base output looks like:

# echo "selclass qualifier memory;info;wait;infolog" | cstm | grep 'Total Configured'
Total Configured Memory : 16384 MB
Total Configured Memory : 16384 MB



Rgds...Geoff

PS: The Hammers...The Hammers are the name of what English football team....What English football team?

Proverbs 3:5,6 Trust in the Lord with all your heart and lean not on your own understanding; in all your ways acknowledge him, and he will make all your paths straight.
Geoff Wild
Honored Contributor

Re: Memory utilization of HP Unix server assign to a variable

For 11.23 and higher, this works:

hexval=$(echo "phys_mem_pages/A" | adb /stand/vmunix /dev/kmem|tail +2|awk '{print $2}')
REAL_MEM=$(echo ${hexval}=D|adb)
mb=$(expr ${REAL_MEM} / 256)
echo $mb

16128

Rgds...Geoff

Proverbs 3:5,6 Trust in the Lord with all your heart and lean not on your own understanding; in all your ways acknowledge him, and he will make all your paths straight.
Hein van den Heuvel
Honored Contributor

Re: Memory utilization of HP Unix server assign to a variable

Geoff, Interesting indeed. On the box i tried, the is no space in between "Memory:".
Looks like there is on yours.

I guess one would have to print $(NF-1) to catch both.

$ uname -a
HP-UX td194 B.11.31 U ia64 3426292962 unlimited-user license
:
Version D.01.00
Product Number B4708AA
:
Basic Memory Description

Module Type: MEMORY
Page Size: 4096 Bytes
Total Physical Memory: N/A
Total Configured Memory: 16384 MB
Total Deconfigured Memory: N/A

Hein.
Nair1980
Frequent Advisor

Re: Memory utilization of HP Unix server assign to a variable

Thank you all for solutions

I was requiring Utilized memory,So I taken in this way

TOTAL=$( echo "selclass qualifier memory;info;wait;infolog" | /usr/sbin/cstm | awk '/Total Configured/{print $5; exit}' )
FREE=$(vmstat | awk '/[0..9]/ { print $5 / 256 }')
((UTIL=TOTAL-FREE))
echo $UTIL


Thanks
Damu
Nair1980
Frequent Advisor

Re: Memory utilization of HP Unix server assign to a variable

TOTAL=$( echo "selclass qualifier memory;info;wait;infolog" | /usr/sbin/cstm | awk '/Total Configured/{print $5; exit}' )
FREE=$(vmstat | awk '/[0..9]/ { print $5 / 256 }')
((UTIL=TOTAL-FREE))
echo $UTIL