#!/bin/bash ######################################################################################################### #barber.greg@gmail.com #copyright 2006 Greg Barber # #This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License along # with this program; if not, write to the Free Software Foundation, Inc., # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. # # #Author: Greg Barber #barber.greg@gmail.com #Purpose: Generate a report of machine name, current kernel release & version and all packages listed in the rpm database. #Changes: 1-17-2007 #Added commands to extract disk information and Logical Volume Management information. #Changes 5-8-2007 #Added commands to extract link speed, duplex, and auto-negotiation information from ethtool #Changes 6-14-2007 #Wasn't parsing all the CPU info fixed in the awk statement #Added functions to allow report to be generated in html format or plain text #Added full path to ethtool was causing an error before the change #Added variable so the report will save to the user's home directory #Changes 9-13-2007 #Changed the call to /sbin/pvdisplay to /sbin/lvm pvdisplay to improve compatibility with RedHat #Changes the call to /sbin/lvdisplay to /sbin/lvm lvdisplay to improve compatibility with RedHat #Added a test so that lvdisplay will not run if there are no physical volumes found #Cleaned up the output by adding spaces between items #Added .html extension to the output of the HTML version of the report #Added a section to list running services #Changes 9-14-2007 #Fixed issue with output of Physical Volumes information appearing on one line #Changes 9-20-2007 #Added a variable to output OS release version (only works with RedHat or SuSE currently) ######################################################################################################## RELEASE=$(uname -r) VERSION=$(uname -v) NODE=$(uname -n) DATE=$(date +%Y-%m-%d) CPU=$(sed -n -e '/model name/p' /proc/cpuinfo | awk '{print $4,$5,$6,$7,$9}') REPORT=$HOME/$NODE-server-report-$DATE #The primary interface will be different if we are running a xen kernel, this will test if we are running a xen kernel and get the proper interface in either case if echo "$RELEASE" | grep -q "xen" then INTERFACE=$(/sbin/ifconfig | sed -n -e '/peth/p' | awk '{print $1}') else INTERFACE=$(/sbin/ifconfig | sed -n -e '/eth/p' | awk '{print $1}') fi #Determind the OS release version if [ -e /etc/SuSE-release ] then OSVER=$(cat /etc/SuSE-release) elif [ -e /etc/redhat-release ] then OSVER=$(cat /etc/redhat-release) else OSVER=$(cat /dev/null) fi IP=$(/sbin/ifconfig | sed -n -e '/Bcast/p' | cut -d : -f 2 | awk '{print $1}') #ethtool needs to be run as root, if not running as root set the variable to a warning message if [ `whoami` = "root" ] then LINK_SPEED=$(/usr/sbin/ethtool $INTERFACE | grep Speed | cut -d : -f 2) else LINK_SPEED="You need to be root to get this information from ethtool" fi #ethtool needs to be run as root, if not running as root set the variable to a warning message if [ `whoami` = "root" ] then DUPLEX=$(/usr/sbin/ethtool $INTERFACE | grep Duplex | cut -d : -f 2) else DUPLEX="You need to be root to get this information from ethtool" fi #ethtool needs to be run as root, if not running as root set the variable to a warning message if [ `whoami` = "root" ] then AUTO_NEG=$(/usr/sbin/ethtool $INTERFACE | grep "Auto-negotiation" | cut -d : -f 2) else AUTO_NEG="You need to be root to get this information from ethtool" fi function usage { echo "Usage: server-report [OPTION] " echo " " echo "Options: " echo " " echo "-p, --plain-text prints a report in plain text format" echo "-H, --html prints a report in html format" echo "-h, --help display this help and exit" echo " " echo "--version output version information and exit" echo " " } function version { echo "server-report version 1.52" echo " " echo "Copyright (C) 2006 Free Software Foundation, Inc. This is free software. You may redistribute copies of it under the terms of the GNU General Public License . There is NO WARRANTY, to the extent permitted by law." echo " " echo "Written by Greg Barber" } function plain { echo -e "\nMACHINE NAME: " $NODE >> $REPORT echo -e "\nCPU INFO: " $CPU >> $REPORT echo -e "\nIP ADDRESS: " $IP >> $REPORT echo -e "\nLINK SPEED: " $LINK_SPEED >> $REPORT echo -e "\nDUPLEX: " $DUPLEX >> $REPORT echo -e "\nAUTO NEGOTIATION: " $AUTO_NEG >> $REPORT echo -e "\nOS RELEASE: " $OSVER >> $REPORT echo -e "\nKERNEL RELEASE: " $RELEASE >> $REPORT echo -e "\nKERNEL VERSION: " $VERSION >> $REPORT echo -e "\nINSTALLED PACKAGES:" >> $REPORT rpm -qa | sort >> $REPORT echo -e `rpm -qa | wc -l` packages installed >> $REPORT echo -e "\nDISK SPACE INFORMATION" >> $REPORT df -h >> $REPORT echo -e "\nLVM (PHYSICAL VOLUMES) INFORMATION">> $REPORT if [ `whoami` = "root" ] then PHY_VOL_INFO=$(/sbin/lvm pvdisplay) if [ "$PHY_VOL_INFO" != "" ] then /sbin/lvm pvdisplay >> $REPORT fi else echo "You need to be root to get this information" >> $REPORT fi echo -e "LVM (LOGICAL VOLUMES) INFORMATION">> $REPORT if [ `whoami` = "root" ] then if [ "$PHY_VOL_INFO" != "" ] then /sbin/lvm lvdisplay >> $REPORT fi else echo "You need to be root to get this information" >> $REPORT fi echo -e "RUNNING SERVICES INFORMATION" >> $REPORT /sbin/chkconfig --list >> $REPORT } function html { echo "" > $REPORT echo "$NODE Server Report" >> $REPORT echo "" >> $REPORT echo "
" >> $REPORT
  echo "REPORT DATE: " `date +%c` >> $REPORT 
  plain
  echo "
" >> $REPORT echo "" >> $REPORT echo "" >> $REPORT mv $REPORT $REPORT.html } if [ "$1" = "-p" ] || [ "$1" = "--plain-text" ] then echo "REPORT DATE: " `date +%c` > $REPORT plain elif [ "$1" = "-H" ] || [ "$1" = "--html" ] then html elif [ "$1" = "-h" ] || [ "$1" = "--help" ] then usage elif [ "$1" = "--version" ] then version else usage fi exit 0