Collect Server Information using Script

#!/bin/sh -e

# This script will collect Server info and it will send a Email
# Author        : Ankam Ravi Kumar
# Date          : 13-March-2015

MAILIST="redhat.ark@gmail.com"
mkdir -p /tmp/asset/
touch /tmp/asset/`hostname`.txt
touch /tmp/temptext
TEMP=/tmp/temptext
LOG=`ls /tmp/asset/*.txt`
echo "## Host Information" > $LOG
echo "Host Name : `hostname` " >> $LOG
echo "`sudo /sbin/ifconfig -a |grep "inet addr" | awk 'BEGIN { FS = ":" } ; { print $2 }'`" >> $TEMP
echo "IP Address : `egrep '^10' $TEMP |awk '{ print $1}'`" >> $LOG

echo -en '\n' >> $LOG

## Colleting Hardware Details ##
echo " " >> $LOG
echo "## Hardware Information" >> $LOG
echo " " >> $LOG
echo "Serial Number     : `lshal |grep system.hardware.serial`" >> $LOG
echo "Serial Number     : `sudo /usr/sbin/dmidecode -s system-serial-number`" >> $LOG
echo "Model Number      : `lshal |grep system.hardware.product`" >> $LOG
echo "Model Number      : `sudo /usr/sbin/dmidecode |grep "SKU Number"`" >> $LOG
echo "Hardware Vendor   : `lshal |grep system.hardware.vendor`" >> $LOG
echo "Hardware Info     : `dmesg |grep DMI`" >> $LOG

## Redhat Version ##
echo " " >> $LOG
echo "## OS Version" >> $LOG
head -n1 /etc/issue >> $LOG
echo -en '\n' >> $LOG
uname -a >> $LOG

## CPU Info ##
echo " " >> $LOG
echo " " >> $LOG
echo "## CPU Information" >> $LOG
grep "model name" /proc/cpuinfo >> $LOG

## RAM/MEMORY Info ##
echo " " >> $LOG
echo " " >> $LOG
echo "## Memory Information" >> $LOG
grep MemTotal /proc/meminfo >> $LOG
y=`grep MemTotal /proc/meminfo |awk '{ print $2 }'`
mb="$(( $y / 1024 ))"
gb="$(( $mb / 1024 ))"
echo "RAM : $gb GB" >> $LOG

## Verify the machine is using NIS ##
echo -en '\n' >> $LOG
cat /etc/yp.conf |grep finnis > /tmp/yptemp.txt
count=`cat /tmp/yptemp.txt | wc -l`
if [ $count -gt 0 ];
then
echo "`hostname` is part of NIS Domain" >> $LOG
cat /etc/yp.conf |grep finnis >> $LOG
else
echo "`hostname` is not part of NIS" >> $LOG
fi

cat /etc/yp.conf |grep domain >> $LOG
/bin/mail -s "Linux Asset Inventory `hostname`" $MAILIST < $LOG

No comments:

Post a Comment