Pular para o conteúdo

Validar memória RAM e swap

Fiz esse script para trazer informações do uso da memória RAM e swap de forma mais amigável.
euteste da silva foxbit3r
Hits: 6.044 Categoria: Shell Script Subcategoria: Avançado
  • Download
  • Nova versão
  • Indicar
  • Denunciar
O Viva o Linux depende da receita de anúncios para se manter. Ative os cookies aqui para nos patrocinar.
Não conseguimos carregar os anúncios. Se usa bloqueador, considere liberar o Viva o Linux para nos patrocinar.

Descrição

Fiz esse script para trazer informações do uso da memória RAM e swap de forma mais amigável.
Download mem.sh Enviar nova versão
O Viva o Linux depende da receita de anúncios para se manter. Ative os cookies aqui para nos patrocinar.
Não conseguimos carregar os anúncios. Se usa bloqueador, considere liberar o Viva o Linux para nos patrocinar.

Esconder código-fonte

#!/bin/bash


function desenharBarra(){

msgMem=$1
valMem=$2
pctVal=$3

   case "$pctVal" in
       [0-9])
           strBar="[ # - - - - - - - - - ]"
       ;;
       1[0-9])
           strBar="[ # # - - - - - - - - ]"
       ;;
       2[0-9])
           strBar="[ # # # - - - - - - - ]"
       ;;
       3[0-9])
           strBar="[ # # # # - - - - - - ]"
       ;;
       4[0-9])
           strBar="[ # # # # # - - - - - ]"
       ;;
       5[0-9])
           strBar="[ # # # # # # - - - - ]"
       ;;
       6[0-9])
           strBar="[ # # # # # # # - - - ]"
       ;;
       7[0-9])
           strBar="[ # # # # # # # # - - ]"
       ;;
       8[0-9])
           strBar="[ # # # # # # # # # - ]"
       ;;
       9[0-9])
           strBar="[ # # # # # # # # # # ]"
       ;;
   esac
   echo "$msgMem ($pctVal%) $strBar $valMem"

}



while read linha;
do
   campo1=$(echo $linha | cut -d " " -f1)

   if [ "$campo1" == "MemTotal:" ];
   then
       MemTotal=$(echo $linha | cut -d " " -f2);
   fi

   if [ "$campo1" == "MemFree:" ];
   then
      MemFree=$(echo $linha | cut -d " " -f2);
   fi

   if [ "$campo1" == "Buffers:" ];
   then
      Buffers=$(echo $linha | cut -d " " -f2);
   fi

   if [ "$campo1" == "Cached:" ];
   then
      Cached=$(echo $linha | cut -d " " -f2);
   fi

   if [ "$campo1" == "SwapTotal:" ];
   then
      SwapTotal=$(echo $linha | cut -d " " -f2);
   fi

   if [ "$campo1" == "SwapFree:" ];
   then
      SwapFree=$(echo $linha | cut -d " " -f2);
   fi


done < /proc/meminfo

MemUsed=$(($MemTotal-$MemFree))

# Calculando o percentual memoria fisica

PctMemFree=$(( $MemFree * 100 / $MemTotal))
PctMemUsed=$(( 100 - $PctMemFree))

# Calculando o percentual do swap.

PctSwapFree=$(( $SwapFree * 100 / $SwapTotal))
PctSwapUsed=$((100 - $PctSwapFree))


# Transformacao para Mbytes

MemTotalMB=$(( $MemTotal / 1024))
MemUsedMB=$((  $MemUsed  / 1024))
MemFreeMB=$((  $MemFree  / 1024))

# Transformacao para Mbytes swap

SwapTotalMB=$(( $SwapTotal / 1024))
SwapFreeMB=$(( $SwapFree / 1024 ))
SwapUsedMB=$(( $SwapTotalMB - $SwapFreeMB ))


printf "Memory Total: %s %s\n" $MemTotalMB "MB"

desenharBarra "Used" "${MemUsedMB} MB" "$PctMemUsed"
desenharBarra "Free" "${MemFreeMB} MB" "$PctMemFree"


printf "\nSwap Memory : %s %s\n" $SwapTotalMB "MB"

desenharBarra "Used" "${SwapUsedMB} MB" "$PctSwapUsed"
desenharBarra "Free" "${SwapFreeMB} MB" "$PctSwapFree"

echo
date
O Viva o Linux depende da receita de anúncios para se manter. Ative os cookies aqui para nos patrocinar.
Não conseguimos carregar os anúncios. Se usa bloqueador, considere liberar o Viva o Linux para nos patrocinar.

Executando comandos remotos usando sshpass

zscan

SCRIPT PARA AUTOMAÇÃO DE ATUALIZAÇÃO EM AMBIENTE DEBIAN OU DERIVADOS.

Troca de link em caso de queda de Internet (FAILOVER)

Atualização para KDE 3.5.1

Nenhum comentário foi encontrado.

Contribuir com comentário

Entre na sua conta para comentar.