Geração de gráfico em shell script
Publicado por Roberto Fettuccia (última atualização em 04/01/2012)
[ Hits: 7.884 ]
Download 1325161950.graficoRAM.sh (versão 2)
Download 1325598901.graficoRAMfinal.sh (versão 3)
Bom resolvi criar este script com a finalidade de ilustrar a taxa de entrada de dados pela placa de rede,
e percebi que este pode também pode desenhar gráficos da memória e etc...
Obs : pode ser adicionado na função "coleta" , o valor a ser igualado a dx deve ser inteiro!
by roberto fettuccia
Versão 2 - Enviado por Roberto Fettuccia em 29/12/2011
Changelog: Nova versão com a leitura da carga do uso da memória RAM...
segue uma prévia...
#!/bin/bash
M=#
Ic=0
colunas=15
operX=$1
timeX='0.4'
unset PP
unset PZ
unset xa[@]
unset xb[@]
unset xc[@]
unset xd[@]
unset xe[@]
unset xf[@]
unset xg[@]
unset xh[@]
unset xi[@]
unset xj[@]
fun.display(){
echo "
Roberto Fettuccia
|_________________________________|
| |
| Grafico bash linux 1.2 RAM |
|_________________________________|
100%| ${xa[@]}
90% | ${xb[@]}
80% | ${xc[@]}
70% | ${xd[@]}
60% | ${xe[@]}
50% | ${xf[@]}
40% | ${xg[@]}
30% | ${xh[@]}
20% | ${xi[@]}
10% | ${xj[@]}
0% |_________________________________
"
}
fun.coleta(){
fun.memory
dx=$percentUSED
sleep $timeX
}
fun.leitura(){
if [ $Ic -ge 0 ] && [ $Ic -lt $colunas ];
then
PZ="$dx"
PP="$Ic"
Ic=$((Ic+1))
else
if [ $Ic -ge $colunas ];
then
PZ="$dx"
PP="$Ic"
Ic=0
fi
fi
}
fun.criavetor(){
for i in $colunas
do
xa[$i]="X"
xb[$i]="X"
xc[$i]="X"
xd[$i]="X"
xe[$i]="X"
xf[$i]="X"
xg[$i]="X"
xh[$i]="X"
xi[$i]="X"
xj[$i]="X"
done
}
fun.biblioteca(){
if [ $PZ -ge 0 ] && [ $PZ -le 9 ];
then
xa[$PP]=" "
xb[$PP]=" "
xc[$PP]=" "
xd[$PP]=" "
xe[$PP]=" "
xf[$PP]=" "
xg[$PP]=" "
xh[$PP]=" "
xi[$PP]=" "
xj[$PP]=" "
fi
if [ $PZ -ge 10 ] && [ $PZ -le 19 ];
then
xa[$PP]=" "
xb[$PP]=" "
xc[$PP]=" "
xd[$PP]=" "
xe[$PP]=" "
xf[$PP]=" "
xg[$PP]=" "
xh[$PP]=" "
xi[$PP]=" "
xj[$PP]="$M"
fi
if [ $PZ -ge 20 ] && [ $PZ -le 29 ] ;
then
xa[$PP]=" "
xb[$PP]=" "
xc[$PP]=" "
xd[$PP]=" "
xe[$PP]=" "
xf[$PP]=" "
xg[$PP]=" "
xh[$PP]=" "
xi[$PP]="$M"
xj[$PP]="$M"
fi
if [ $PZ -ge 30 ] && [ $PZ -le 39 ];
then
xa[$PP]=" "
xb[$PP]=" "
xc[$PP]=" "
xd[$PP]=" "
xe[$PP]=" "
xf[$PP]=" "
xg[$PP]=" "
xh[$PP]="$M"
xi[$PP]="$M"
xj[$PP]="$M"
fi
if [ $PZ -ge 40 ] && [ $PZ -le 49 ];
then
xa[$PP]=" "
xb[$PP]=" "
xc[$PP]=" "
xd[$PP]=" "
xe[$PP]=" "
xf[$PP]=" "
xg[$PP]="$M"
xh[$PP]="$M"
xi[$PP]="$M"
xj[$PP]="$M"
fi
if [ $PZ -ge 50 ] && [ $PZ -le 59 ];
then
xa[$PP]=" "
xb[$PP]=" "
xc[$PP]=" "
xd[$PP]=" "
xe[$PP]=" "
xf[$PP]="$M"
xg[$PP]="$M"
xh[$PP]="$M"
xi[$PP]="$M"
xj[$PP]="$M"
fi
if [ $PZ -ge 60 ] && [ $PZ -le 69 ];
then
xa[$PP]=" "
xb[$PP]=" "
xc[$PP]=" "
xd[$PP]=" "
xe[$PP]="$M"
xf[$PP]="$M"
xg[$PP]="$M"
xh[$PP]="$M"
xi[$PP]="$M"
xj[$PP]="$M"
fi
if [ $PZ -ge 70 ] && [ $PZ -le 79 ];
then
xa[$PP]=" "
xb[$PP]=" "
xc[$PP]=" "
xd[$PP]="$M"
xe[$PP]="$M"
xf[$PP]="$M"
xg[$PP]="$M"
xh[$PP]="$M"
xi[$PP]="$M"
xj[$PP]="$M"
fi
if [ $PZ -ge 80 ] && [ $PZ -le 89 ];
then
xa[$PP]=" "
xb[$PP]=" "
xc[$PP]="$M"
xd[$PP]="$M"
xe[$PP]="$M"
xf[$PP]="$M"
xg[$PP]="$M"
xh[$PP]="$M"
xi[$PP]="$M"
xj[$PP]="$M"
fi
if [ $PZ -ge 90 ] && [ $PZ -le 99 ];
then
xa[$PP]=" "
xb[$PP]="$M"
xc[$PP]="$M"
xd[$PP]="$M"
xe[$PP]="$M"
xf[$PP]="$M"
xg[$PP]="$M"
xh[$PP]="$M"
xi[$PP]="$M"
xj[$PP]="$M"
fi
if [ $PZ -ge 100 ] ;
then
xa[$PP]="$M"
xb[$PP]="$M"
xc[$PP]="$M"
xd[$PP]="$M"
xe[$PP]="$M"
xf[$PP]="$M"
xg[$PP]="$M"
xh[$PP]="$M"
xi[$PP]="$M"
xj[$PP]="$M"
fi
}
fun.main(){
fun.coleta
fun.leitura
fun.biblioteca
clear
fun.display
fun.main
}
fun.memory(){
T=$(free -m | sed 2q | sed 1D | awk '{print $2}')
U=$(free -m | sed 2q | sed 1D | awk '{print $3}')
percentUSED="$(($U/($T/100)))"
}
fun.main
Download 1325161950.graficoRAM.sh
Versão 3 - Enviado por Roberto Fettuccia em 03/01/2012
Changelog:
Após inúmeras alterações, acabei por desenvolver uma versão mais simplificada, sem o uso de código mais expressivo, que resultou em uma melhoria na performance, sem a necessidade de instruções "pesadas".
Agora o usuário pode operar com este script sem muita dificuldade, inclusive poderá alterar os caracteres que desenha o gráfico, segue a nova cara do script...
_________________________________
| |
| Grafico bash linux 1.3F RAM |
|_________________________________|
100%| □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ |
95% | □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ |
90% | □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ |
85% | □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ |
80% | □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ |
75% | □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ |
70% | □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ |
65% | □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ |
60% | □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ |
55% | □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ |
50% | □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ |
45% | □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ |
40% | □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ |
35% | □ □ □ □ □ □ □ □ □ □ □ □ □ □ ◼ □ |
30% | □ □ □ □ □ □ □ □ ◼ □ □ □ □ □ ◼ □ |
25% | □ ◼ □ □ □ □ □ ◼ ◼ □ □ □ □ ◼ ◼ □ |
20% | ◼ ◼ □ ◼ □ ◼ ◼ ◼ ◼ □ ◼ ◼ ◼ ◼ ◼ □ |
15% | ◼ ◼ ◼ ◼ □ ◼ ◼ ◼ ◼ ◼ ◼ ◼ ◼ ◼ ◼ ◼ |
10% | ◼ ◼ ◼ ◼ ◼ ◼ ◼ ◼ ◼ ◼ ◼ ◼ ◼ ◼ ◼ ◼ |
5% | ◼ ◼ ◼ ◼ ◼ ◼ ◼ ◼ ◼ ◼ ◼ ◼ ◼ ◼ ◼ ◼ |
0% |_________________________________|
Modo de operação..
etapas
1 - leitura de dados a ser calculado em %
2 - calculo de dados em %
3 - alocado caractere no inicio de cada vetor
4 - apagado posição final do vetor com o valor $colunas (para não pular a tela)
5 - desenha todos os vetores
6 - reinicia cadeia de processo, pula para etapa 1.
Obs : estou utilizando funções para facilitar o processo de loop, assim não precisa ser utilizado loop aritimético, case, for, wile...
Para não gerar uma carga excessiva do processador não coloque o valor de timeX menor que 5, isso aumenta o tempo entre cada leitura..
By roberto fettuccia
Download 1325598901.graficoRAMfinal.sh
#!/bin/bash M=# Ic=0 colunas=15 unset PP unset PZ unset xa[@] unset xb[@] unset xc[@] unset xd[@] unset xe[@] unset xf[@] unset xg[@] unset xh[@] unset xi[@] unset xj[@] fun.display(){ echo " |_________________________________| | | | Grafico bash linux 1.0 | |_________________________________| 100%| ${xa[@]} 90% | ${xb[@]} 80% | ${xc[@]} 70% | ${xd[@]} 60% | ${xe[@]} 50% | ${xf[@]} 40% | ${xg[@]} 30% | ${xh[@]} 20% | ${xi[@]} 10% | ${xj[@]} 0% |_________________________________ " } fun.coleta(){ echo valor 0 a 100 : read dx # Entrada valor inteiro } fun.leitura(){ if [ $Ic -ge 0 ] && [ $Ic -lt $colunas ]; then PZ="$dx" PP="$Ic" Ic=$((Ic+1)) else if [ $Ic -ge $colunas ]; then PZ="$dx" PP="$Ic" Ic=0 fi fi } fun.criavetor(){ for i in $colunas do xa[$i]="X" xb[$i]="X" xc[$i]="X" xd[$i]="X" xe[$i]="X" xf[$i]="X" xg[$i]="X" xh[$i]="X" xi[$i]="X" xj[$i]="X" done } fun.biblioteca(){ if [ $PZ -ge 0 ] && [ $PZ -le 9 ]; then xa[$PP]=" " xb[$PP]=" " xc[$PP]=" " xd[$PP]=" " xe[$PP]=" " xf[$PP]=" " xg[$PP]=" " xh[$PP]=" " xi[$PP]=" " xj[$PP]=" " fi if [ $PZ -ge 10 ] && [ $PZ -le 19 ]; then xa[$PP]=" " xb[$PP]=" " xc[$PP]=" " xd[$PP]=" " xe[$PP]=" " xf[$PP]=" " xg[$PP]=" " xh[$PP]=" " xi[$PP]=" " xj[$PP]="$M" fi if [ $PZ -ge 20 ] && [ $PZ -le 29 ] ; then xa[$PP]=" " xb[$PP]=" " xc[$PP]=" " xd[$PP]=" " xe[$PP]=" " xf[$PP]=" " xg[$PP]=" " xh[$PP]=" " xi[$PP]="$M" xj[$PP]="$M" fi if [ $PZ -ge 30 ] && [ $PZ -le 39 ]; then xa[$PP]=" " xb[$PP]=" " xc[$PP]=" " xd[$PP]=" " xe[$PP]=" " xf[$PP]=" " xg[$PP]=" " xh[$PP]="$M" xi[$PP]="$M" xj[$PP]="$M" fi if [ $PZ -ge 40 ] && [ $PZ -le 49 ]; then xa[$PP]=" " xb[$PP]=" " xc[$PP]=" " xd[$PP]=" " xe[$PP]=" " xf[$PP]=" " xg[$PP]="$M" xh[$PP]="$M" xi[$PP]="$M" xj[$PP]="$M" fi if [ $PZ -ge 50 ] && [ $PZ -le 59 ]; then xa[$PP]=" " xb[$PP]=" " xc[$PP]=" " xd[$PP]=" " xe[$PP]=" " xf[$PP]="$M" xg[$PP]="$M" xh[$PP]="$M" xi[$PP]="$M" xj[$PP]="$M" fi if [ $PZ -ge 60 ] && [ $PZ -le 69 ]; then xa[$PP]=" " xb[$PP]=" " xc[$PP]=" " xd[$PP]=" " xe[$PP]="$M" xf[$PP]="$M" xg[$PP]="$M" xh[$PP]="$M" xi[$PP]="$M" xj[$PP]="$M" fi if [ $PZ -ge 70 ] && [ $PZ -le 79 ]; then xa[$PP]=" " xb[$PP]=" " xc[$PP]=" " xd[$PP]="$M" xe[$PP]="$M" xf[$PP]="$M" xg[$PP]="$M" xh[$PP]="$M" xi[$PP]="$M" xj[$PP]="$M" fi if [ $PZ -ge 80 ] && [ $PZ -le 89 ]; then xa[$PP]=" " xb[$PP]=" " xc[$PP]="$M" xd[$PP]="$M" xe[$PP]="$M" xf[$PP]="$M" xg[$PP]="$M" xh[$PP]="$M" xi[$PP]="$M" xj[$PP]="$M" fi if [ $PZ -ge 90 ] && [ $PZ -le 99 ]; then xa[$PP]=" " xb[$PP]="$M" xc[$PP]="$M" xd[$PP]="$M" xe[$PP]="$M" xf[$PP]="$M" xg[$PP]="$M" xh[$PP]="$M" xi[$PP]="$M" xj[$PP]="$M" fi if [ $PZ -ge 100 ] ; then xa[$PP]="$M" xb[$PP]="$M" xc[$PP]="$M" xd[$PP]="$M" xe[$PP]="$M" xf[$PP]="$M" xg[$PP]="$M" xh[$PP]="$M" xi[$PP]="$M" xj[$PP]="$M" fi } fun.main(){ fun.coleta fun.leitura fun.biblioteca clear fun.display fun.main } fun.main
Liberação do servidor DNS no firewall
Tradução de endereços de uma rede interna
Conciliando o uso da ZRAM e SWAP em disco na sua máquina
Servidor de Backup com Ubuntu Server 24.04 LTS, RAID e Duplicati (Dell PowerEdge T420)
Visualizar câmeras IP ONVIF no Linux sem necessidade de instalar aplicativos
Realizar overclock no Miyoo Mini (plus ou normal)
Otimização de memória para máquinas modestas
Monitoramento pfsense com zabbix (0)
Dúvidas sobre a originalidade de conteúdos online (5)
Google Crhome não abre desde que eu atualizei pelo "program... (3)
como instalar o amdgpu no linux manjaro no linux, pelo o repo e comand... (4)