Script filtro de informações de hardware

De Wiki Hackstore

#!/bin/bash

# remove extra whitespace
crunch() {
        while read FOO ; do
              echo $FOO
        done
        }

echo -e "* Hackstore - System Info\n\nNome do servidor: $(hostname)\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n"
echo -e "* Marca do hardware:\n$(dmidecode -t 1|grep Manufacturer: -A1|crunch|sed s,'Manufacturer:','Fabricante:',g|sed s,'Product Name:','Modelo:',g)\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n"
echo -e "* Processador(es):\nNúmero de processadores: $(cat /proc/cpuinfo|grep "physical id"|sort|uniq|wc -l)\nModelo: $(cat /proc/cpuinfo|grep model\ name|crunch|sort|uniq|sed s,'model name : ',,g)\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n"
echo -e "* Dispositivos de rede:\n$( lspci |grep Ethernet\ controller|cut -d: -f3|crunch)\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n"
echo -e "* Memória RAM:\nFrequência: $(dmidecode -t 17|grep Speed:|uniq|crunch|grep -i MHz|sed s,'Speed: ',,g)\nTipo: $(dmidecode -t 17|grep Type:|uniq|crunch|sed s,'Type: ',,g)\nQuantidade total detectada: $(awk -v memory_total="$(echo $(grep -i memtotal /proc/meminfo|cut -d: -f2|sed s,kB,,g|crunch)*1024|bc)" 'BEGIN{sum=memory_total; hum[1024**3]="Gb";hum[1024**2]="Mb";hum[1024]="Kb"; for (x=1024**3; x>=1024; x/=1024){ if (sum>=x) { printf "%.2f %s\n",sum/x,hum[x];break } }}'|tr [a-z] [A-Z])\nCapacidade máxima suportada: $(dmidecode -t 16|grep 'Maximum Capacity:'|crunch|sed s,'Maximum Capacity: ',,g)\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n"

parted -l|grep Disk|cut -d":" -f1|cut -d" " -f2|grep -vi flags|sort > /tmp/lista-discos.txt
echo -e "* Armazenamento (HDs):\n$(while read DISCO a;do  echo -e "$(parted $DISCO print|grep Disk|grep -vi flags |crunch|sed s,'device size with M = 1000\*1000: ',,g)" ;done < /tmp/lista-discos.txt ; rm /tmp/lista-discos.txt)\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n"


#awk -v memory_total="$(echo $(grep -i memtotal /proc/meminfo|cut -d: -f2|sed s,kB,,g|crunch)*1024|bc)" 'BEGIN{sum=memory_total; hum[1024**3]="Gb";hum[1024**2]="Mb";hum[1024]="Kb"; for (x=1024**3; x>=1024; x/=1024){ if (sum>=x) { printf "%.2f %s\n",sum/x,hum[x];break } }}'|tr [a-z] [A-Z]