Saber los recursos del pc: recursos.sh

Por Paco Aldarias Raya

Impreso: 7 de septiembre 2008

Email: pacolinux arroba inicia punto es

Web: http://aldarias.es/pacodebian

Con Linux Debian. En Valencia (España)

El documento tiene version .html, y .pdf, cambiando en el navegador la parte final podrás acceder a ambos.

Este documento es de libre reproducción siempre que se cite su fuente.

Realizado con: LATEX

Índice General

1 Introducción

Vamos a ver la forma de poder ver el estado de nuestra maquina

2 Instalación

apt-get install iptotal

3 El script

cat recursos.sh

#!/bin/bash
# Por Paco Aldarias.
# 12.4.06
# recursos.sh
echo "********************************************************************************************"

h=$(hostname)
echo "* NOMBRE PC [$h]"

kernel=$(uname -mnrs)
tpo=$(uptime | cut -d "," -f1)
usu=$(users)
echo "* TIEMPO [ENCENDIDO $tpo]"
echo "* [USUARIOS: $usu]"
echo "* [KERNEL: $kernel]"

cpui=$(cat /proc/cpuinfo | grep "model name" | tail -f -n 1 |  cut -c 14-)
#usuario=$(atsar -u 1 3 | tail -n 1 |  awk -F " " '{print $2}')
#sistema=$(atsar -u 1 3 | tail -n 1 |  awk -F " " '{print $4}')
#total=$(expr $usuario + $sistema)
#echo "* CPU: [$cpui]  [Usuario: $usuario %] [Sistema $sistema %] [Total: $total %]"

memt=$(/usr/bin/free | grep "Mem" | awk -F " " '{print $2}')
memf=$(/usr/bin/free | grep "Mem" | awk -F " " '{print $3}')
mems=$(/usr/bin/free | grep "Swap" | awk -F " " '{print $2}')
echo "* MEMORIA: [Total $memt] [Fisica usada: $memf] [Swap usada: $mems]"

ip0=`/sbin/ifconfig eth0 | grep "inet addr:" | awk '{print $2}' | cut -c  6-`
mac0=`/sbin/ifconfig eth0 | grep "HWaddr" | awk '{print $5}'`
ad0=$(lspci  | grep Ethernet | sed -e 2d | cut  -c 35-)
/usr/sbin/iptotal -r 5 eth0 > iptotal.txt
in0=`cat iptotal.txt |  awk '{print $5}'`
out0=`cat iptotal.txt |  awk '{print $8}'`
echo "* RED ETH0: [IP: $ip0] [MAC: $mac0]"
echo "[Tarjeta: $ad0] "
# [Entra: $in0 KB/s] [Sale: $out0 KB/s]

ip1=`/sbin/ifconfig eth1 | grep "inet addr:" | awk '{print $2}' | cut -c  6-`
if [ -z $ip1 ]; then
mac1=`/sbin/ifconfig eth1 | grep "HWaddr" | awk '{print $5}'`
ad1=$(lspci | grep Ethernet | sed -e 1d | cut  -c 35-)
#/usr/sbin/iptotal -r 5 eth1 > iptotal.txt
#in1=`cat iptotal.txt |  awk '{print $5}'`
#out1=`cat iptotal.txt |  awk '{print $8}'`
#echo "* RED ETH1 [IP: $ip1]  [MAC: $mac1] [Tarjeta: $ad1]  [Entra: $in1 KB/s] [Sale: $out1 KB/s]"
fi

ps aux  > procesos.txt 2>/dev/null
total=`wc -l < procesos.txt`
total=`expr $total - 1`
ps aux  | grep root  > procesos.txt 2>/dev/null
root=`wc -l < procesos.txt`
root=`expr $root - 2`
echo "* PROCESOS: [total: $total] [Root: $root]"
#cat top.txt | sed -e '1,7d' | head -f 1

#hda1t=$(df | grep hda1  | awk '{print $2}')
#hda1u=$(df | grep hda1  | awk '{print $3}')
#hda1d=$(df | grep hda1  | awk '{print $4}')
#echo "* HDA1: [total: $hda1t] [Usado: $hda1u]  [Disponible: $hda1d] "
echo "* DISCOS: "
df
echo "********************************************************************************************"

4 Version reducida

#!/bin/bash
# Por Paco Aldarias.
# 12.4.06
# recursos.sh

h=$(hostname)
kernel=$(uname -mnrs)
cpui=$(cat /proc/cpuinfo | grep "model name" | cut -d ":" -f2 | cut -d " " -f2)
frecuencia=$(cat /proc/cpuinfo  | awk ' /MHz/ {print $4} ')
memt=$(/usr/bin/free | grep "Mem" | awk -F " " '{print $2}')
grafica=$(lspci  | grep VGA | cut -d ":" -f3 )

mac0=$(dmesg  | grep "eth0:" | awk ' /IRQ/ {print $6}' | cut -d "," -f1)
ip0=$(/sbin/ifconfig eth0 | grep "inet addr:" | awk '{print $2}' | cut -d ":" -f2)
mod0=$(dmesg  | grep "eth0:" | awk ' /IRQ/ {print $2 " " $3}' | cut -d "," -f1 )

mac1=$(dmesg  | grep "eth1:" | awk ' /IRQ/ {print $6}' | cut -d "," -f1)
ip1=$(/sbin/ifconfig eth1 | grep "inet addr:" | awk '{print $2}' | cut -d ":" -f2)
mod1=$(dmesg  | grep "eth1:" | awk ' /IRQ/ {print $2 " " $3}' | cut -d "," -f1 )

hda=$(fdisk -l /dev/hda | grep -v "cylinders" |  awk '/bytes/ {print $3 } ')
hdb=$(fdisk -l /dev/hdb | grep -v "cylinders" |  awk '/bytes/ {print $3 } ')
sda=$(fdisk -l /dev/sda | grep -v "cylinders" |  awk '/bytes/ {print $3 } ')
sdb=$(fdisk -l /dev/sdb | grep -v "cylinders" |  awk '/bytes/ {print $3 } ')

echo "HOSTNAME  : $h"
echo "KERNEL    : $kernel"
echo "CPU       : $cpui $frecuencia Mz"
echo "RAM       : $memt"
echo "GRAFICA   : $grafica"
if [ -n "$mod0" ];then echo "ETH0      : $mod0 $mac0 $ip0"; fi
if [ -n "$mod1" ];then echo "ETH1      : $mod1 $mac1 $ip1"; fi
if [ ! -z $hda ];then echo "DISCO hda : $hda GB"; fi
if [ ! -z $hdb ];then echo "DISCO hdb : $hdb GB"; fi
if [ ! -z $sda ];then echo "DISCO sda : $sda GB"; fi
if [ ! -z $sdb ];then echo "DISCO sdb : $sdb GB"; fi

5 Ejecución

chmod 700 recursos.sh
./recursos.sh

Índice de Materias

Sobre este documento...

Saber los recursos del pc: recursos.sh

This document was generated using the LaTeX2HTML translator Version 2002-2-1 (1.71)

Copyright © 1993, 1994, 1995, 1996, Nikos Drakos, Computer Based Learning Unit, University of Leeds.
Copyright © 1997, 1998, 1999, Ross Moore, Mathematics Department, Macquarie University, Sydney.

The command line arguments were:
latex2html recursos -split 0 -local_icons 1 -show_section_numbers -no_auto_link -no_navigation

The translation was initiated by Paco on 2008-09-07


Paco 2008-09-07