Results 1 to 7 of 7
I would like to make a script (bash) to display the memory in GB, MB and KB.
For example, If I take 1049132Mb, the result are:
1GB, 5Mb and 0 ...
- 11-21-2008 #1Just Joined!
- Join Date
- Oct 2008
- Posts
- 48
Display the memory in Gb, Mb and Kb
I would like to make a script (bash) to display the memory in GB, MB and KB.
For example, If I take 1049132Mb, the result are:
1GB, 5Mb and 0 Kb
Is it possible to make it??
thanks!
- 11-21-2008 #2Linux Newbie
- Join Date
- Jul 2008
- Posts
- 181
Of course it is possible. You can use "free", or "vmstat" or "cat /proc/meminfo" to get an overview of memory use, for example, and the operators "%" and "/" to split the result into appropriate chunks.
- 11-21-2008 #3Just Joined!
- Join Date
- Oct 2008
- Posts
- 48
I have this:
MEMTOTAL=`free | grep Mem | awk '{ print $2 }'`
MEMUSED=`free | grep Mem | awk '{ print $3 }'`
MEMFREE=`free | grep Mem | awk '{ print $4 }'`
echo "Total: "`expr $MEMTOTAL / 1048576`"Gb"
echo "Used: "`expr $MEMUSED / 1024`"Mb" "($MEMUSED Kb)"
echo "Free: "`expr $MEMFREE / 1024`"Mb" "($MEMFREE Kb)"
but i don't know to split and convert to my idea...
- 11-21-2008 #4Just Joined!
- Join Date
- Jul 2007
- Posts
- 49
If you use free with the switches -k -m -g it will give you the output you desire, there is more info on the switches you can use in the man pages for the free command.
- 11-23-2008 #5Just Joined!
- Join Date
- Oct 2008
- Posts
- 48
but i necesary to split the result...
- 11-24-2008 #6Linux Newbie
- Join Date
- Jul 2008
- Posts
- 181
Yes, but that's just elementary math.
- 11-24-2008 #7Just Joined!
- Join Date
- Oct 2008
- Posts
- 48
anybody know any script already done?


Reply With Quote