#!/bin/sh
#last update 2013/08/21
###start
###前提条件,运行脚本机器与被统计机器ssh必须互相信任(id_rsa)
. /etc/rc.d/init.d/functions
. /etc/sysconfig/network
if [ $# -eq 0 ];then
echo -n "Please specify hosts: "
read hosts
if [ -z $hosts ];then
echo -e "\033[40;31mexit..... \033[0m"
exit 2
else
export hosts
fi
else
hosts=$1
export hosts
fi
echo -n "Testing to $hosts ..."
daemon "ssh -i /root/id_rsa $hosts -p 8000 'ls' > /dev/null"
retval=$?
echo
echo
echo
if [ $retval -eq 0 ];then
echo "**********************************************"
echo "Hostanem: `ssh -i /root/id_rsa $hosts -p 8000 'hostname'` "
xinghao=`ssh -i /root/id_rsa $hosts -p 8000 '/usr/sbin/dmidecode |grep "Product Name"| head -1'`
model=`echo $xinghao | awk -F ":" '{print $2}'`
export model
echo "Product Name:$model"
echo
echo
echo "**********************************************"
echo "IP Info:"
echo "`ssh -i /root/id_rsa $hosts -p 8000 '/sbin/ip add | grep "inet"| grep -v "127.0"| grep -v "inet6"'| awk -F " " '{print $2}'|awk -F "/" '{print $1}'`"
echo
echo
echo "**********************************************"
echo "Disk Info:"
echo "`ssh -p 8000 -i /root/id_rsa $hosts '/sbin/fdisk -l| egrep "GB|MB"'| awk '{print $3$4}' | uniq -c|sed -e 's/\,//'`"
echo
echo
echo "**********************************************"
echo "CPU Info:"
echo " Physics Num: ` ssh -p 8000 -i /root/id_rsa $hosts 'cat /proc/cpuinfo '|grep "physical id"|sort |uniq|wc -l`"
echo " Logic Num: ` ssh -p 8000 -i /root/id_rsa $hosts 'cat /proc/cpuinfo '|grep "processor"|wc -l`"
echo " CPU Cores: ` ssh -p 8000 -i /root/id_rsa $hosts 'cat /proc/cpuinfo '|grep "cores"|uniq|awk '{print $4}'`"
echo " Model Name : ` ssh -p 8000 -i /root/id_rsa $hosts 'cat /proc/cpuinfo '|grep "GHz"|uniq|awk -F ":" '{print $2}'`"
echo
echo
echo "**********************************************"
echo "Mem Info:"
echo " ` ssh -p 8000 -i /root/id_rsa $hosts 'free -m'|sed '1d'| awk '{print $2}'| head -1` M"
echo
echo
hostname=`ssh -i /root/id_rsa $hosts -p 8000 'hostname'`
lanip=`ssh -i /root/id_rsa $hosts -p 8000 '/sbin/ip add | grep "inet"| egrep "192.168.0|10.1.1"|grep -v "127.0"| grep -v "inet6"'| awk -F " " '{print $2}'|awk -F "/" '{print $1}'`
wan1=`ssh -i /root/id_rsa $hosts -p 8000 '/sbin/ip add | grep "inet"| grep "220.181."|grep -v "127.0"| grep -v "inet6"'| awk -F " " '{print $2}'|awk -F "/" '{print $1}'`
wan2=`ssh -i /root/id_rsa $hosts -p 8000 '/sbin/ip add | grep "inet"| grep "61.135.208."|grep -v "127.0"| grep -v "inet6"'| awk -F " " '{print $2}'|awk -F "/" '{print $1}'`
if [ -z $wan1 ];then
wanip=$wan2
export wanip
elif [ -z $wan2 ];then
wanip=$wan1
export wanip
else
wanip="$wan1/$wan2"
export wanip
fi
***ip="`ssh -i /root/id_rsa $hosts -p 8000 '/sbin/ip add | grep "inet"| grep "193.16"|grep -v "127.0"| grep -v "inet6"'| awk -F " " '{print $2}'|awk -F "/" '{print $1}'`"
echo
echo
echo -n "Please input cpu: "
read cpu
echo
echo -n "Please input mem: "
read mem
echo
echo -n "Please input disk: "
read disk
view(){
echo
echo -n "Please input hostname: "
read hostname
echo
echo -n "Please input model: "
read model
echo -n "Please input wanip: "
read wanip
echo
echo -n "Please input lanip: "
read lanip
echo
echo -n "Please input ***ip: "
read ***ip
echo
echo -n "Please input cpu: "
read cpu
echo
echo -n "Please input mem: "
read mem
echo
echo -n "Please input disk: "
read disk
echo
echo " ------------------------------------------------------ "
echo " Hostname: $hostname "
echo " Model : $model "
echo " LANIP : $lanip "
echo " WANIP : $wanip "
echo " ×××IP : $***ip "
echo " CPU : $cpu "
echo " MEM : $mem "
echo " DISK : $disk "
echo " ------------------------------------------------------ "
echo -n "Please verify! [Yes/No/Alter]: "
read verify
echo
if [ -z $verify ];then
sql
echo
else
if [ $verify = Yes ] || [ $verify = y ] || [ $verify = yes ];then
sql
echo
else
if [ $verify = Alter ] || [ $verify = a ];then
view
else
echo -e "\033[40;31mexit... \033[0m"
exit 2
fi
fi
fi
}
sql(){
echo -n "Insert to databases... "
daemon "mysql -u root -pangel -e \"insert into hostsdb.hosts(model,hostname,wanip,lanip,***ip,cpu,mem,disk) values('$model','$hostname','$wanip','$lanip','$***ip','$cpu','$mem','$disk');\""
echo
}
echo " ------------------------------------------------------ "
echo " Hostname: $hostname "
echo " Model : $model "
echo " LANIP : $lanip "
echo " WANIP : $wanip "
echo " ×××IP : $***ip "
echo " CPU : $cpu "
echo " MEM : $mem "
echo " DISK : $disk "
echo " ------------------------------------------------------ "
echo -n "Please verify! [Yes/No/Alter]: "
read verify
echo
if [ -z $verify ];then
sql
echo
else
if [ $verify = Yes ] || [ $verify = y ] || [ $verify = yes ];then
sql
echo
else
if [ $verify = Alter ] || [ $verify = a ];then
view
else
echo -e "\033[40;31mexit... \033[0m"
exit 2
fi
fi
fi
else
exit 2
fi
###end