cat /proc/meminfo | awk '/MemTotal:/ {
m = $2
f = m /= 1024 # Mb
f /= 1024 # Gb
}
END {printf "%0.f\n", f }'
on my machine I get 16 = 16 Gb
From: Patrick Lists <ks-list@xxxxxxxxxxxxxxxxx>
To: jamesaharrisonuk@xxxxxxxxxxx; Discussion list about Kickstart <kickstart-list@xxxxxxxxxx>
Sent: Tue, December 21, 2010 8:10:07 AM
Subject: Re: Detecting amount of memory?
On 12/21/2010 01:39 PM, jamesaharrisonuk@xxxxxxxxxxx wrote:
> The kernel reports the amount of memory in /proc/meninfo . It shows the memory information in kilobytes.
> James
> Sent from my Verizon Wireless BlackBerry
Thank you for your suggestion James. I tried it out and /proc/meminfo
seems to give the same amount of memory as free:
$ grep "MemTotal" /proc/meminfo | awk '{ print $2 }'
6123716
Fortunately I did find some awk voodoo that works. For the archives here
it is. Mind the line breaks. Line 2,3,4 should be all one line.
mem=$(free|grep Mem|awk '{print$2}')
echo "$mem" | awk '{ n = $0; sub(/[0-9]+(.[0-9]+)?/, ""); split(n, a,
$0); n=a[1]; if ($0 == "G" || $0 == "") { n *= 1024 }; if (/^kB?/) { n
/= 1024 }; printf "%d\n", n }'
# Intentionaly round to an integer
This line gives 6144 on a box with 6GB mem.
Regards,
Patrick
[snip]
m = $2
f = m /= 1024 # Mb
f /= 1024 # Gb
}
END {printf "%0.f\n", f }'
on my machine I get 16 = 16 Gb
From: Patrick Lists <ks-list@xxxxxxxxxxxxxxxxx>
To: jamesaharrisonuk@xxxxxxxxxxx; Discussion list about Kickstart <kickstart-list@xxxxxxxxxx>
Sent: Tue, December 21, 2010 8:10:07 AM
Subject: Re: Detecting amount of memory?
On 12/21/2010 01:39 PM, jamesaharrisonuk@xxxxxxxxxxx wrote:
> The kernel reports the amount of memory in /proc/meninfo . It shows the memory information in kilobytes.
> James
> Sent from my Verizon Wireless BlackBerry
Thank you for your suggestion James. I tried it out and /proc/meminfo
seems to give the same amount of memory as free:
$ grep "MemTotal" /proc/meminfo | awk '{ print $2 }'
6123716
Fortunately I did find some awk voodoo that works. For the archives here
it is. Mind the line breaks. Line 2,3,4 should be all one line.
mem=$(free|grep Mem|awk '{print$2}')
echo "$mem" | awk '{ n = $0; sub(/[0-9]+(.[0-9]+)?/, ""); split(n, a,
$0); n=a[1]; if ($0 == "G" || $0 == "") { n *= 1024 }; if (/^kB?/) { n
/= 1024 }; printf "%d\n", n }'
# Intentionaly round to an integer
This line gives 6144 on a box with 6GB mem.
Regards,
Patrick
[snip]
_______________________________________________ Kickstart-list mailing list Kickstart-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/kickstart-list