Find the answer to your Linux question:
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 ...
  1. #1
    Just 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!

  2. #2
    Linux 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.

  3. #3
    Just 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...

  4. #4
    Just 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.

  5. #5
    Just Joined!
    Join Date
    Oct 2008
    Posts
    48
    but i necesary to split the result...

  6. #6
    Linux Newbie
    Join Date
    Jul 2008
    Posts
    181
    Yes, but that's just elementary math.

  7. #7
    Just Joined!
    Join Date
    Oct 2008
    Posts
    48
    anybody know any script already done?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...