shell-script-pt
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [shell-script] Calculo com variáveis


From: Tiago Barcellos Peczenyj
Subject: Re: [shell-script] Calculo com variáveis
Date: Tue, 13 Feb 2007 16:46:33 -0200

Ola, vc pode usar bc + here strings

bc <<< "scale=10(( ${memtotal} -( ${memfree} + ${buffree}))/ ${memtotal})*100"

ou awk puro, usando NR para identificar a linha ;)

awk 'NR==2{ m_total = $2; m_livre = $4;}
NR == 3{ b_livre = $4}
END{
   print "o resultado eh: ",100*((m_total - (m_livre + b_livre))/m_total)
}' saida.out

On 2/13/07, williansantunes <address@hidden> wrote:






Olá pessoal,

 Estou com a seguinte necessidade. Preciso obter o resultado da
 expressão  abaixo:

 topmem = ((memtotal -(memfree+buffree))/memtotal)*100

 as variáveis foram declaradas assim:

 memtotal=`head -2 saida.out |tail -1 |awk '{print $2}'`
 memused=`head -2 saida.out |tail -1 |awk '{print $3}'`
 memfree=`head -2 saida.out |tail -1 |awk '{print $4}'`

 bufused=`head -3 saida.out |tail -1 |awk '{print $3}'`
 buffree=`head -3 saida.out |tail -1 |awk '{print $4}'`

 swaptotal=`head -4 saida.out |tail -1|awk '{print $2}'`
 swapused=`head -4 saida.out |tail -1|awk '{print $3}'`
 swapfree=`head -4 saida.out |tail -1|awk '{print $4}'`

 Qual a melhor maneira de fazer isso? BC? Expr? outra ?

 Abraços! E desde já muito obrigado!

 Willians




--
Tiago B Peczenyj
Linux User #405772

# cd /pub
# more beer


reply via email to

[Prev in Thread] Current Thread [Next in Thread]