码迷,mamicode.com
首页 > 系统相关 > 详细

查看linux系统的信息

时间:2018-01-19 14:09:41      阅读:197      评论:0      收藏:0      [点我收藏+]

标签:iat   iss   via   host   net   print   clear   filename   pre   

#!/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

  

查看linux系统的信息

标签:iat   iss   via   host   net   print   clear   filename   pre   

原文地址:https://www.cnblogs.com/jycjy/p/8316031.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!