#!/bin/sh ################################################## #function:get host's information #Author:eric-chen export filename filename=linuxHostInfo.dat datadir=./ echo -n "">$datadir$filename function WriteIndex() { datadir=./ time=`date +%Y-%m-%d" "%H:%M:%S` firstipadd=`ifconfig -a|grep "inet addr"|awk -F ":" '{print $2}'|awk '{if ( NR==1 )print $1}'` echo -e ",,$firstipadd,Linux,$2,$3,$time,$1|">>$datadir$filename } export -f WriteIndex function GetHostinfo() { HostOS=`cat /etc/issue |sed -n '1p'` #echo $HostOS WriteIndex "$HostOS" "" HostOS HostModel=`dmidecode|grep "Product Name"|sed -n '1p'|awk -F ":" '{print $2}'` WriteIndex "$HostModel" "" HostModel HostName=`hostname` WriteIndex $HostName "" HostName IPAddress=`ifconfig -a|grep "inet addr"|awk -F ":" '{print $2}'|awk '{if ( NR==1 )print $1}'` WriteIndex $IPAddress "" IPAddress KernelVersion=`cat /proc/version|awk '{print $3}'` WriteIndex $KernelVersion "" KernelVersion OSBits=`getconf LONG_BIT` WriteIndex $OSBits "" OSBits CpuNumber=`cat /proc/cpuinfo|grep "processor"|wc -l` WriteIndex $CpuNumber "" CpuNumber Uptime=`cat /proc/uptime| awk -F. '{run_days=$1 / 86400;run_hour=($1 % 86400)/3600;run_minute=($1 % 3600)/60;printf("%d天%d小时%d分",run_days,run_hour,run_minute)}'` WriteIndex $Uptime "" Uptime HostTime=`date +%Y-%m-%d" "%H:%M:%S` WriteIndex "$HostTime" "" HostTime RemoteTime=$1 HostSecondTime=`date +%s` Deviation=`echo $(($HostSecondTime-$RemoteTime))|awk -F. '{run_days=$1 / 86400;run_hour=($1 % 86400)/3600;run_minute=($1 % 3600)/60;run_second=$1 % 60;printf("%d天%d小时%d分%d秒",run_days,run_hour,run_minute,run_second)}'` WriteIndex "$Deviation" "" HostTimeDeviation } GetHostinfo "$@" clear cat $filename