#!/bin/bash #检查系统信息 #2016-09-21 #Version 2.0.1 #检查当前用户是否为root if [ `id -u` -ne 0 ] then echo ‘请使用root用户执行脚本!‘; exit 11; fi release_file=‘/etc/redhat-release‘; smart_bin=`which smartctl 2>/dev/null`; dmi_bin=`which dmidecode 2>/dev/null`; #smart=null; diskinfo=(`fdisk -l|awk ‘FS="[ :,.]+"{if($0~/Disk \/.+\/[a-z]+:/){print $2":"$3$5}}‘`); #检查是否安装"smartmontools","smartmontools"包含smartctl if [ -n $smart_bin ] then smart=true; fi #检查是否安装"dmidecode" if [ -n $dmi_bin ] then dmi=true; fi if [ -e $release_file ] then echo ‘操作系统名称:‘`cat $release_file`; fi if [ $dmi == ‘true‘ ] then echo -ne ‘主板信息:\n‘; dmidecode -t 2|awk ‘FS=":"{if($0~/Manufacturer/ && $2 !~/Not Specified/){manufacturer=$2;}if($0~/Product Name/ && $2 !~/Not Specified/){product=$2;}}END{print manufacturer" --"product;}‘; echo -ne ‘内存信息:\n‘; dmidecode -t 17|awk ‘FS=":"{if($0 ~"Size:" && $2 !~ / No Module Installed/){num=NR+9}if(NR>num){b=0}else{b=1}}b{if($0 ~/Size:/ || $0 ~/[^ ]Speed:/ || $0 ~/Manufacturer:/){gsub(/\s/,"",$0);print $0}}‘; fi echo -ne ‘处理器信息:\n‘; awk ‘FS=": "{if($1~"model name"){print $2}}‘ /proc/cpuinfo; echo -ne ‘磁盘驱动:\n‘; #输出数组中的内容 for dev in ${diskinfo[*]} do dev_num=`echo $dev|cut -d‘:‘ -f1`; dev_type=`smartctl -i $dev_num|awk ‘FS=":"{if($1~"Device Model"){print $2}}‘`; if [ $smart == ‘true‘ ] then echo -ne $dev_type"\n"; echo -ne $dev"\n"; else echo -ne $dev"\n"; fi done echo -ne ‘网络适配器:\n‘; lspci|awk ‘FS=":"{if($0~"Ethernet controller"){print $3}}‘ echo if [ $smart == ‘null‘ -o $dmi == ‘null‘ ] then echo ‘如需获取详细信息请使用"smartmontools"和"dmidecode"工具‘ fi
运行结果:
本文出自 “小陌成长之路” 博客,请务必保留此出处http://309173854.blog.51cto.com/7370240/1855117
原文地址:http://309173854.blog.51cto.com/7370240/1855117