这个脚本适用于统计系统信息的
适用版本:Centos6、Centos7
#!/bin/bash
#
#********************************************************************
#encoding -*-utf8-*-
#Author: zhangshang
#Date: 2017-11-25
#URL: http://blog.vservices.top/myblog
#Description: 显示当前主机系统信息
#Copyright (C): 2017 All rights reserved
#QQ Numbers: 765030447
#********************************************************************
echo -e "\033[31m**********************System info**************************\033[0m"
#主机名
echo -e "\033[33mHostname:\033[0m\033[32m`hostname`\033[0m"
#网卡IP
echo -e "\033[33mIPV4 Address\033[0m"
#取出网卡名
for i in `ifconfig | tr -s '[:blank:]' | grep ^[[:alnum:]] | cut -d: -f1`
do
ipaddr=`ifconfig | grep -A 1 $i | grep inet | grep netmask | awk '{print $2}'`
echo -e "\t$i:\t\033[32m$ipaddr\033[0m"
done
unset i
#系统版本
echo -e "\033[33mSystem_version:\t\033[0m\033[32mCentos `cat /etc/centos-release | grep -o "[[:digit:]]\+\.[[:digit:]]\+"`\033[0m"
#内核版本
echo -e "\033[33mKernel_version:\t\033[0m\033[32m`uname -r`\033[0m"
#CPU型号
echo -e "\033[33mCPU Model:\t\033[0m \033[32m`cat /proc/cpuinfo | grep name | cut -d: -f2`\033[0m"
#内存信息
echo -e "\033[33mMemery_Size\t\033[0m"
(( mem_total=`cat /proc/meminfo | grep MemTotal | awk '{print $2}'` / 1024 ))
(( mem_free=`cat /proc/meminfo | grep MemFree | awk '{print $2}'`/ 1024 ))
(( swap_total=`cat /proc/meminfo | grep SwapTotal | awk '{print $2}'` / 1024 ))
(( swap_free=`cat /proc/meminfo | grep SwapFree | awk '{print $2}'` / 1024 ))
echo -e "\tTotal_mem:\t\033[32m$mem_total MB\033[0m"
echo -e "\tFree_mem:\t\033[32m$mem_free MB\033[0m"
echo -e "\tTotal_swap:\t\033[32m$swap_total MB\033[0m"
echo -e "\tFree_swap:\t\033[32m$swap_free MB\033[0m"
unset mem_total mem_free swap_total swap_free
#硬盘信息
echo -e "\033[33mHarddisk_info\033[0m"
#根分区信息
rootinfo=`df -B g | grep "/$" | awk '{print "\ttotal_size:",$2,"\t\tused_ratio:",$5}'`
rootinode=`df -i -h| grep "/$" | awk '{print "\ttotal_inodes:",$2,"\t\tused_inodes_ratio:",$5}'`
echo -e "\t\\ \033[32m\t$rootinfo\033[0m"
echo -e "\t\033[32m\t$rootinode\033[0m"
#其他分区信息
for i in `df -B G | grep /dev/sd | grep -v "/$" | awk '{print $1}'`
do
echo -e "\t$i\033[32m`df -B G | grep $i | awk '{print "\ttotal_size:",$2,"\t\t\tused_ratio:",$5}'`\033[0m"
echo -e "\t\033[32m\t`df -i -h | grep $i | awk '{print "\ttotal_inodes:",$2,"\t\tused_inodes_ratio:",$5}'`\033[0m"
done
unset rootinfo rootinode i
结果
**********************System info**************************
Hostname:joker-7-01
IPV4 Address
ens33: 192.168.253.129
lo: 127.0.0.1
System_version: Centos 7.4
Kernel_version: 3.10.0-693.el7.x86_64
CPU Model: Intel(R) Core(TM) i7-7500U CPU @ 2.70GHz
Memery_Size
Total_mem: 976 MB
Free_mem: 554 MB
Total_swap: 2047 MB
Free_swap: 2047 MB
Harddisk_info
\ total_size: 50G used_ratio: 9%
total_inodes: 25M used_inodes_ratio: 1%
/dev/sda1 total_size: 1G used_ratio: 16%
total_inodes: 512K used_inodes_ratio: 1%
文档更新时间: 2018-12-12 20:52 作者:张尚