LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (http://www.linuxquestions.org/questions/programming-9/)
-   -   Script to calculate installed memory. (http://www.linuxquestions.org/questions/programming-9/script-to-calculate-installed-memory-872828/)

pobrika 04-04-2011 05:23 AM

Script to calculate installed memory.
 
Hello,

I am trying to write a script to calculate the total amount of installed memory to use during an anaconda kickscript, so the swap file is created at 2 x the installed memory.

I so far have the amount of installed RAM DIMMS but need a way to total them up and produce a varible I can use in the pre section of the install.
Code:

dmidecode -t 17 | grep Size | awk ' { print $2 }'
Output:
2048
2048

Note: on some servers there could be from 1 DIMM up to 16 DIMMS installed so the script needs to be able to handle this. I also can not use bc as it does not exist during the install stage.

I am guessing I need a while loop to do this and use expr but do not know where to start for this logic.

Cheers

Guttorm 04-04-2011 06:02 AM

Hi

Why not read /proc/meminfo?

Code:

grep MemTotal /proc/meminfo

pobrika 04-04-2011 06:32 AM

Quote:

Originally Posted by Guttorm (Post 4313182)
Hi

Why not read /proc/meminfo?

Code:

grep MemTotal /proc/meminfo

Unfortunately during the boot stage the kernel can only address maximum of 4GB so dmidecode is the only way to tell how much is really in the server.

Guttorm 04-04-2011 06:59 AM

Hmm. If you just want the sum, awk can calculate it.

Code:

dmidecode -t 17 | grep Size | awk '{ SUM += $2} END { print SUM }'


All times are GMT -5. The time now is 10:49 AM.