Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I know some of you might find my question stupid but i need to know how much ram is installed on a centos box Yes i know it can easily be done by using the command

awk '/MemTotal/{print $2}' /proc/meminfo

However the problem is that the memory shown is not really want i need.The value shown will always be less than expected as some ram is used to load the kernel.Thus a 512 MB ram server will always show a little less than 524288 kb.

The reason while i need the full physical ram is very simple.I need to modify settings automatically on a box via my bash script. Thus if server has total 512 MB ram , one set of setting is used , if 1gb then another.....

I cannot gamble with the value return by the command above as value varies from system to system.

Any good valid option guys.......

Kind Regards

share|improve this question
    
    
I know comparison with bash ...question is not about bash command here.I need an ssh commmand that can get me the true physical ram installed on server –  Werulz Mar 6 '13 at 17:22
add comment

1 Answer

up vote 4 down vote accepted

Here you go... From my larger script at: Documenting server details

# Calculate installed RAM
dmidecode -t 17 | awk '( /Size/ && $2 ~ /^[0-9]+$/ ) { x+=$2 } END{ print "\t" "Installed Ram: " x "MB"}'

Output: Installed Ram: 28672MB (or divide by 1024)

share|improve this answer
    
Thanks so much.However i need to installed dmidecode then...i though it could be without any 3rd party.Dude can you modify the command so that it output only 28672 and not "Installed Ram:" and MB(its for convenience.... –  Werulz Mar 6 '13 at 17:28
    
I haven't learn awk yet , i know only sed for now....regards ewwhite –  Werulz Mar 6 '13 at 17:33
    
@Werulz dmidecode -t 17 | awk '( /Size/ && $2 ~ /^[0-9]+$/ ) { x+=$2 } END{ print x }' –  ewwhite Mar 6 '13 at 17:36
    
Bro i have a little question about your command.It may happen that dmidecode contain Size multiple times like in thegeekstuff.com/2008/11/… .Do the command automatically add all values of "Size"....Thanks –  Werulz Mar 7 '13 at 5:09
    
@Werulz Yes. That's what happens. –  ewwhite Mar 7 '13 at 12:31
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.