Find the answer to your Linux question:
Results 1 to 3 of 3
I would like to know the % free memory and the % busy . Is it possible with bash? I have this: #! /bin/bash clear MEMTOTAL=`free | grep Mem | ...
  1. #1
    Just Joined!
    Join Date
    Oct 2008
    Posts
    48

    memory en linux

    I would like to know the % free memory and the % busy. Is it possible with bash?
    I have this:


    #! /bin/bash
    clear

    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 / 1024`"Mb" "($MEMTOTAL Kb)"> file.txt
    echo "Usada: "`expr $MEMUSED / 1024`"Mb" "($MEMUSED Kb)" >> file.txt
    echo "Libre: "`expr $MEMFREE / 1024`"Mb" "($MEMFREE Kb)" >> file.txt
    echo " " >> file.txt
    more "file.txt"


    thanks!

  2. #2
    Linux Newbie
    Join Date
    Jul 2008
    Posts
    181
    Code:
    free | awk '/^Mem:/ { print "used: " 100*$3/$2 "%  free: " 100*$4/$2 "%"; }'

  3. #3
    Just Joined!
    Join Date
    Oct 2008
    Posts
    48
    i change a little:

    [guif@jirabck Escritorio]$ free | awk '/Mem:/ {print "used: " 100*$3/$2 "%";}'
    used: 97,2066%
    [guif@jirabck Escritorio]$
    [guif@jirabck Escritorio]$ free | awk '/Mem:/ {print "free: " 100*$4/$2 "%";}'
    free: 2,79499%

    this is correct???

    and, in my code:

    echo "`expr $MEMTOTAL / $MEMFREE`"%"

    this is the used memory??? the result is different!

Posting Permissions

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