User Tools

Site Tools


sys2wiki.sh

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Next revision
Previous revision
sys2wiki.sh [2005/10/15 13:46] Stynosys2wiki.sh [2007/12/20 03:44] (current) 211.161.7.147
Line 1: Line 1:
 +====== sys2wiki.sh ======
  
 +Script to output some hardware info under linux in a [[wiki:DokuWiki]] compatible format. 
 +
 +I added MHz and delete the blank in the CPU variable.
 +
 +<code bash>
 +#!/bin/bash
 +
 +#make sure tools work as expected
 +LANG=C
 +
 +#this specifies which Headline level is used
 +HL='===='
 +
 +CPU=`cat /proc/cpuinfo  | grep 'model name' | awk -F\: '{print $2}'|uniq|sed -e 's/ //'`
 +MHz=`cat /proc/cpuinfo | grep 'cpu MHz' | awk -F\: '{print $2}'|uniq|sed -e 's/ //'`
 +CPUCOUNT=`cat /proc/cpuinfo|grep "physical id"|uniq|wc -l`
 +RAM=`cat /proc/meminfo | grep MemTotal | awk -F\: '{print $2}' | awk -F\  '{print $1 " " $2}'`
 +SWAP=`cat /proc/meminfo | grep SwapTotal | awk -F\: '{print $2}' | awk -F\  '{print $1 " " $2}'`
 +SYSTEM=`uname -sr`
 +HOSTNAME=`(hostname -f || hostname) 2>/dev/null`
 +
 +# look for known Distributions
 +if [ -e /etc/debian_version ]; then
 +  OS="Debian `cat /etc/debian_version`"
 +elif [ -e /etc/redhat-release ]; then
 +  OS=`cat /etc/redhat-release`
 +elif [ -e /etc/SuSE-release ]; then
 +  OS=`cat /etc/SuSE-release |head -n1`
 +elif [ -e /etc/gentoo-release ]; then
 +  OS=`< /etc/gentoo-release`
 +else
 +  OS='unknown'
 +fi
 +
 +echo "
 +$HL General $HL
 +
 +^ Hostname | $HOSTNAME |
 +^ CPU      | $CPU      |
 +^ MHz      | $MHz      |
 +^ # CPU    | $CPUCOUNT |
 +^ RAM      | $RAM      |
 +^ Swap     | $SWAP     |
 +^ System   | $SYSTEM   |
 +^ OS       | $OS       |
 +"
 +
 +echo -e "$HL Network $HL\n"
 +for DEV in `/sbin/ifconfig -a |grep '^\w'|awk '!/lo/{print $1}'`
 +do
 +  IP=`/sbin/ifconfig $DEV |awk -F\: '/inet / {print $2}'|awk '{print $1}'`
 +  echo "^ $DEV | $IP |"
 +done
 +echo
 +
 +echo -e "$HL PCI $HL\n"
 +lspci |sed 's/^/  /'
 +echo
 +
 +echo -e "$HL Filesystems $HL\n"
 +df -hPT -x tmpfs | awk '{print "| " $1 " | " $2 " | " $3 " | " $7 " |"}'
 +echo
 +
 +echo -e "$HL IDE devices $HL\n"
 +
 +for DEV in `ls -1d /proc/ide/hd* |sed 's/.*\///'`
 +do
 +  MODEL=`cat /proc/ide/$DEV/model`
 +  if [ -e /proc/ide/$DEV/capacity ]; then
 +    SIZE=`cat /proc/ide/$DEV/capacity`
 +    SIZE=`expr $SIZE / 2097152`
 +  else
 +    if [ -e /sys/block/$DEV/size ]; then
 +      SIZE=`cat /sys/block/$DEV/size`
 +      SIZE=`expr $SIZE / 2097152`
 +    else
 +      SIZE='(unknown)'
 +    fi
 +  fi
 +
 +  echo "| /dev/$DEV | $MODEL | $SIZE GB |"
 +done
 +
 +if [ "$(ls -1d /sys/block/sd* 2> /dev/null)" ]; then 
 +  echo -e "$HL SCSI devices $HL\n"
 +  for DEV in `ls -1d /sys/block/sd* |sed 's/.*\///'`
 +  do
 +    MODEL=`cat /sys/block/$DEV/device/model`
 +    SIZE=`cat /sys/block/$DEV/size`
 +    SIZE=`expr $SIZE / 2097152`
 +
 +    echo "| /dev/$DEV | $MODEL | $SIZE GB |"
 +  done
 +  echo
 +fi
 +</code>
 +
 +----
 +Cool! I had forgotten you posted this. Here's a diff to add Slackware "detection" and format the lspci output:
 +<file>
 +--- sys2wiki.sh.orig    2006-08-26 22:13:48.000000000 -0400
 ++++ sys2wiki.sh 2006-08-26 22:14:04.000000000 -0400
 +@@ -23,6 +23,8 @@
 +   OS=`cat /etc/SuSE-release |head -n1`
 + elif [ -e /etc/gentoo-release ]; then
 +   OS=`< /etc/gentoo-release`
 ++elif [ -e /etc/slackware-version ]; then
 ++  OS=`< /etc/slackware-version`
 + else
 +   OS='unknown'
 + fi
 +@@ -49,7 +51,8 @@
 + echo
 +  
 + echo -e "$HL PCI $HL\n"
 +-lspci |sed 's/^/  /'
 ++echo " Bus Address  ^  Device Class  ^  Details  ^"
 ++lspci |sed 's/\([0-9a-f]\{2\}:[0-9a-f]\{2\}.[0-9a-f]\)\([a-zA-Z0-9 ]\+\):\(.*\)$/ \1  | \2  |  \3  |/g'
 + echo
 +  
 + echo -e "$HL Filesystems $HL\n"
 +</file>
 +--N1XIM
 +-- fixing the sed script to accept hex numbers
 +
 +
 +  CPUKENELCOUNT=`cat /proc/cpuinfo|grep "processor"|uniq|wc -l`
 +  .....
 +  ^ # CPUKENEL | $CPUKENELCOUNT |
 +
 +-- sinosmond
 +-- add  CPU KENEL COUNT
 +----
 +
 +If you want to use sys2wiki.sh on a remote server and using a crontab, you might want to have a look at the [[wiki:tips:tofromdoku|Dokuwiki Command Line Utility]]