LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
LinkBack Search this Thread
Old 04-04-2011, 04:23 AM   #1
pobrika
Member
 
Registered: Jan 2008
Location: Bournemouth, UK
Distribution: Mint, #!, Fedora, Redhat, Centos
Posts: 64

Rep: Reputation: 18
Question 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
 
Old 04-04-2011, 05:02 AM   #2
Guttorm
Senior Member
 
Registered: Dec 2003
Location: Trondheim, Norway
Distribution: Debian and Ubuntu
Posts: 1,089

Rep: Reputation: 207Reputation: 207Reputation: 207
Hi

Why not read /proc/meminfo?

Code:
grep MemTotal /proc/meminfo
 
Old 04-04-2011, 05:32 AM   #3
pobrika
Member
 
Registered: Jan 2008
Location: Bournemouth, UK
Distribution: Mint, #!, Fedora, Redhat, Centos
Posts: 64

Original Poster
Rep: Reputation: 18
Quote:
Originally Posted by Guttorm View Post
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.
 
Old 04-04-2011, 05:59 AM   #4
Guttorm
Senior Member
 
Registered: Dec 2003
Location: Trondheim, Norway
Distribution: Debian and Ubuntu
Posts: 1,089

Rep: Reputation: 207Reputation: 207Reputation: 207
Hmm. If you just want the sum, awk can calculate it.

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


Reply

Tags
shell script


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Script to calcualte installed memory. pobrika Programming 7 04-04-2011 12:00 PM
[SOLVED] How to calculate flash memory end address of a certain file? jaepi Programming 6 03-15-2011 12:28 AM
Calculate total memory consumed by user emymcse Linux - General 12 09-23-2010 05:26 AM
how to calculate memory available if needed on a linux system? icekiss Linux - Server 1 07-16-2010 06:52 AM
How to calculate cpu and memory usage of a process narendra1310 Ubuntu 1 08-30-2008 02:39 AM


All times are GMT -5. The time now is 08:13 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration