Sysinfo versão 0.7

Publicado por Denis Doria 22/09/2008

[ Hits: 5.133 ]

Download sysinfo.sh




Atualização do script sysinfo.sh:

http://vivaolinux.com.br/script/Sysinfo-Informacoes-sobre-o-seu-computador

Essa atualização corrige um BUG, e também traz algumas modificações no código original, além de melhorar algumas formas de capturar as informações do computador.

  



Esconder código-fonte

#!/bin/bash

##########################################################################################
#Sysinfo - Get a lot of information about the system
#
#Version: 0.7
#
#Author: Denis Doria de Oliveira Santos
#E-mail: denisdoria@gmail.com
#Date: 11/09/2008
###########################################################################################
#Version: 0.1
#
# +Create all base system, with the functions that I need
#
###########################################################################################
#Version: 0.2
#
# +Add getopts
# +Add usage function
# +Improved memory function
#
###########################################################################################
#Version: 0.3
#
# + Improved os information, the os function was copied from hinventory_Linux.sh
#   all hinventory code can be find in http://sourceforge.net/projects/h-inventory/,
#   some modification was done from the original code.
# +Improved memory function
# -Removed hwmisc function
#
###########################################################################################
#Version: 0.4
#
# + Created pci function
# + Improved memory function
#
###########################################################################################
#Version: 0.5
# 
# +Improved network function
# +Improved memory function
# +Improved os function (I prefer the new style)
#
###########################################################################################
#Version 0.6
#
# -Removed the hinventory os function (thanks your code help me very much :-)) )
# +Improved os function with the lsb_release (how could I live without this command???)
#
###########################################################################################
#Version 0.7
#
#* BUG FIXED - (BUG REPORT) CPU info have problem when the numbers of processor is
#              different than the number of chips in the mother board.
#
###########################################################################################

[ $(whoami) != 'root' ] && echo -e "\nJust root can run this script...\nSorry, but some commands just root could exec!\n" && exit 1


A=0
S=0
C=0
M=0
N=0
D=0
O=0
B=0
H=0
W=0
P=0

function network(){
   
   #Catch all ips and interfaces
   #Captura todos os ips e suas interfaces
   echo "[Network]"

   #Get all interfaces
   ifconfig |cut -d' ' -f1|sed '/^$/d'|\
   while read INTERFACE;
   do
      #For each interface get the ip
      IP=$(ifconfig|fgrep -A1 -m1 ${INTERFACE}|tail -1|cut -d: -f2|awk '{print $1}')         
      echo -e "${INTERFACE}\\t${IP}";

   done
   echo ""
   lspci|fgrep Ethernet|cut -d' ' -f2-
   echo ""

}

function system(){

   #Show information about system
   #Mostra informações do sistema
   echo "[System]"
   dmidecode |grep -A4 "System Information"|sed '1d'|tr -d '\t'
   echo ""

}

function memory(){
   
   #Information about memory, number of slots and memory size
   #Informações sobre a memória, número de slots, tamanho da memória
   echo "[Memory]"
   dmidecode |sed -ne '/Physical Memory Array/,/Handle /p'|egrep '(Maximum Capacity|Number Of Devices)'|tr -d '\t'
   #dmidecode |grep -A5 "Memory Device$"|fgrep Size|tr -d '\t'
   #dmidecode|sed -n '/Memory Device$/,/Handle /p'|fgrep Size|tr -d '\t'| tee /dev/stderr |awk -F':| ' '{print $3}'|tr -d [:alpha:]|tr '\n' '+'|sed 's/+*$/\n/'|bc
   dmidecode|sed -n '/Memory Device$/,/Handle /p'|fgrep Size|tr -d '\t'
   
   echo ""
   #sed -e '1!d' -e 's/..$//' -e 's/ //g' /proc/meminfo |awk -F: '{print $1": "$2/1024" MB"}'
   #fgrep MemTotal /proc/meminfo|awk -F':| ' '{print "Total Of Memory: "int($8/1024)}'
   sed -e '/MemTotal:/!d' -e 's/ //g' /proc/meminfo |awk -F: '{print $1": "$2/1024" MB"}'
   echo ""

}

function cpu(){
   
   #Information about processor
   #Infomações sobre o processador
   echo "[CPU]"
   dmidecode |sed -ne '/Processor Information/,/Handle/p' |sed -e '/\t\t\t/d' |tr -d '\t'|\
   egrep '(Manufacturer:|Current Speed:|Family:|Socket Designation:)'|sed -e 's/\(MHz\)/\1\n/' -e 's/\(GHz\)/\1\n/'
   local NUCLEOS=$(grep processor /proc/cpuinfo |wc -l)
   local CHIPS=$(dmidecode |fgrep "Processor Information"|wc -l)
   local CHIPS_ATIVOS=$(dmidecode  |sed -ne '/Processor Information/,/Handle/p' |fgrep 'Current Speed'|grep -v 'Current Speed:.*Unknown'|wc -l)
   local NUCLEOS_POR_PROCESSADOR=$((NUCLEOS/CHIPS_ATIVOS))
   
   echo "Number of Sockets: "$CHIPS
   echo "Number of Processors:"$CHIPS_ATIVOS
   echo "Core per Processor: "$NUCLEOS_POR_PROCESSADOR
   echo ""
}

function disk() {

   #Information about disks
   #Informações sobre os discos   
   echo "[Disk]"

   #For each disk
   fdisk -l 2> /dev/null|grep "Disk.*,"|cut -d, -f1 |\
   while read LINHA
   do
      #Show the partitions of each disk
      echo -e "${LINHA}\n"
      printf "%-9s%12s%12s\n" 'Device' 'Size' 'Type' &&\
      fdisk -l 2> /dev/null|fgrep $(echo $LINHA|awk -F" |:" '{print $2}')|tr -d '*'|\
      fgrep -v Disk|\
      awk '{printf("%9s %10s MB %10s\n", $1,int($4/1024),$6)}'   

      echo ""

   done
   
   echo ""

}

function swap(){

   #Information about swap
   #Informação sobre o swap
   echo "[Swap]"
   fgrep -m1 dev "/proc/swaps"|awk '{print "Swap Particion: "$1"\nSwap Space: "int($3/1024)" MB"}'
   echo ""

}

function os (){


   #Check the version and the distribution of Linux
   #Verifica a versão e a distribuição Linux

NAME=$(uname -s)

if [ "$NAME" = "Linux" ];then

   #if [ -f /etc/redhat-release ]; then
   #            DISTRIBUTION="RedHat"
   #             RELEASE=$(cat /etc/redhat-release)
   #         elif [ -f /etc/redhat-version ]; then
   #             DISTRIBUTION="RedHat"
   #             RELEASE=$(cat /etc/redhat-version)
   #         elif [ -f /etc/fedora-release ]; then
   #             DISTRIBUTION="Fedora"
   #             RELEASE=$(cat /etc/fedora-release)
   #         elif [ -f /etc/mandrake-release ]; then
   #             DISTRIBUTION="Mandrake"
   #             RELEASE=$(cat /etc/mandrake-release)
   #         elif [ -f /etc/SuSE-release ]; then
   #             DISTRIBUTION="Novell SuSE"
   #             RELEASE=$(cat /etc/SuSE-release)
   #         elif [ -f /etc/debian_version ]; then
   #             DISTRIBUTION="Debian"
   #             RELEASE=$(cat /etc/debian_version)
   #         elif [ -f /etc/debian-version ]; then
   #             DISTRIBUTION="Debian"
   #             RELEASE=$(cat /etc/debian-version)
   #         elif [ -f /etc/arch-release ]; then
   #             DISTRIBUTION="Arch"
   #             RELEASE=$(cat /etc/arch-release)
   #         elif [ -f /etc/gentoo-release ]; then
   #             DISTRIBUTION="Gentoo"
   #             RELEASE=$(cat /etc/gentoo-release)
   #         elif [ -f /etc/slackware-release ]; then
   #             DISTRIBUTION="Slackware"
   #             RELEASE=$(cat /etc/slackware-release)
   #         elif [ -f /etc/slackware-version ]; then
   #             DISTRIBUTION="Slackware"
   #             RELEASE=$(cat /etc/slackware-version)
   #         elif [ -f /etc/yellowdog-release ]; then
   #             DISTRIBUTION="Yellow dog"
   #             RELEASE=$(cat /etc/yellowdog-release)
   #         elif [ -f /etc/sourcemage-release ]; then
   #             DISTRIBUTION="Source Mage"
   #            RELEASE=$(cat /etc/sourcemage-release)
   #         elif [ -f /etc/smgl.iso ]; then
   #             DISTRIBUTION="Source Mage"
   #             RELEASE=$(cat /etc/smgl.iso)
   #          else DISTRIBUTION="unknown"
   #             RELEASE="unknown"
   #     fi

   echo "[Operating System]"
   echo "Hostname: $(hostname)"
   echo "Kernel Version: $(uname -r)"
   lsb_release -irc
   #echo "Operating System: $NAME" 
   #echo "Distribution: $DISTRIBUTION"
   #echo "Release: $RELEASE"

   

fi

echo ""

}

function hba(){

   echo "[HBA]"
   lspci|fgrep -m1 "Fibre Channel"|cut -d' ' -f2-
   echo ""

}

function usage(){

echo -e '\t-a Show all information
\t-s Show system information
\t-c Show CPU information
\t-m Show memory information
\t-n Show network information
\t-d Show disks information
\t-w Show swap information
\t-b Show HBA information
\t-o Show Operating System information\n'

}

function all(){
   
   os
   system
   cpu
   disk
   memory
   pci
   network
   swap
   hba

}

function pci(){

   echo "[PCI]"   
   dmidecode |sed -ne '/PCI/,/Handle /p'|egrep '(Current)'|tr -d '\t'

   echo ""

   echo "Total of PCI: $(dmidecode |sed -ne '/PCI/,/Handle /p'|egrep '(Current)'|tr -d '\t'|wc -l)"

   echo ""
}

function sysinfo(){

   [ $H -eq 1 ] && usage && exit 0
   [ $A -eq 1 ] && all && exit 0
   [ $S -eq 1 ] && system
   [ $C -eq 1 ] && cpu
   [ $M -eq 1 ] && memory
   [ $N -eq 1 ] && network
   [ $D -eq 1 ] && disk
   [ $W -eq 1 ] && swap
   [ $O -eq 1 ] && os
   [ $B -eq 1 ] && hba
   [ $P -eq 1 ] && pci

   exit 0

}

while getopts 'aschmndwobp' OPT
do

   case $OPT in
      
      a) A=1 #all
      ;;
      s) S=1 #system
      ;;
      c) C=1 #cpu
      ;;
      m) M=1 #memory
      ;;
      n) N=1 #network
      ;;
      d) D=1 #disk
      ;;
      w) W=1 #swap
      ;;
      o) O=1 #os
      ;;
      b) B=1 #hba
      ;;
      h) H=1 #usage      
      ;;
      p) P=1 #pci
      ;;
      ?) usage && exit 1
      ;;

   esac

done

sysinfo

exit 0

Scripts recomendados

Script contra ataques de Brutal Force por SSH.

Conecção banda larga!

Script p/ instalar modem onboards

IP Info - Pesquisa geográfica pelo endereço IP

INSTALA TAR GZ COM MENU GRÁFICO ZENITY


  

Comentários
[1] Comentário enviado por kalib em 22/09/2008 - 15:05h

Show de bola...bem bacana esse script. ;]


Contribuir com comentário




Patrocínio

Site hospedado pelo provedor RedeHost.
Linux banner
Linux banner
Linux banner

Destaques

Artigos

Dicas

Tópicos

Top 10 do mês

Scripts