shell写的检测linux系统硬件信息的脚本
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
shell写的检测linux系统硬件信息的脚本
前面用python写了一个检测windonws硬件信息的脚本,这里是很久之前用shell写的一个linux系统硬件信息检测脚本,可以对照看一下。检测内容基本一样:操作系统信息、内存、CPU、硬盘分区及挂载情况,网卡配置情况、安装的软件信息等。
1.#!/bin/bash
2.#This script is used to check the server
3.#system info
4.system_info() {
5.echo "**********************************************"
6.echo "system info:"
7.echo
8.echo " System-release : `cat /etc/redhat-release`"
9.echo " Kernel-release : `uname -a|awk '{print $1,$3}'`"
10.echo " Server-
Model : `dmidecode | grep "Product Name:"|sed -n '1p'|awk -
F': ' '{print $2}'`"
11.echo
12.}
13.
14.
15.
16.
17.#CPU info
18.cpu_info() {
19.echo "**********************************************"
20.echo "CPU info:"
21.echo
22.echo " Frequency : `cat /proc/cpuinfo | grep "model name
" | uniq |awk -F': ' '{print $2}'`"
23.echo " CPU cores: `cat /proc/cpuinfo | grep "cpu cores"
| uniq |awk -F': ' '{print $2}'`"
24.echo " Logic Count : `cat /proc/cpuinfo | grep "processo
r" | sort -u| wc -l `"
25.echo " Physical Count : `cat /proc/cpuinfo | grep "physi
cal" | sort -u| wc -l`"
26.echo " Cache size : `cat /proc/cpuinfo| grep "cache size
"|uniq|awk '{print $4,$5}'`"
27.echo
28.}
29.
30.
31.
32.
33.
34.#memory info
35.mem_info() {
36.memory=`dmidecode |grep "Range Size"|head -
1|awk '{print $3$4}'`
37.mem_size=`echo "This server has ${memory} memory."`
38.
39.echo "**********************************************"
40.echo "Memory info:"
41.echo
42.echo " Total : ${mem_size}"
43.echo " Count : `dmidecode |grep -
A16 "Memory Device$"|grep Size|awk '{if($2!~/No/) print $0}'|wc -l`"
44.dmidecode |grep -
A20 "Memory Device$"|grep Size|sed '{s/^ */ /g};{/No/d}'
45.echo
46.}
47.
48.
49.
50.
51.
52.#disk and partitions
53.swap_pos=`cat /proc/swaps|sed -n '2p'|awk '{print $1}'`
54.partition_info() {
55.echo "**********************************************"
56.echo "Hard disk info:"
57.echo
58.echo "`fdisk -l|grep Disk|awk -F, '{print $1}'`"
59.echo "**********************************************"
60.echo "Partition info:"
61.echo
62.df -h | grep -v Filesystem | sed "s:none:${swap_pos}:"
63.echo
64.}
65.
66.
67.#network adapter info
68.adapter_info() {
69.
70.duplex_eth0=`ethtool eth0 | grep Duplex | awk '{if($2~/Full
/) print "Full"};{if($2~/Half/)print "Half"};{if($2~/Uknown!/) prin t "unknown"}'`
71.
72.duplex_eth1=`ethtool eth1 | grep Duplex | awk '{if($2~/Full
/) print "Full"};{if($2~/Half/)print "Half"};{if($2~/Uknown!/) prin t "unknown"}'`
73.
74.Negotiation_eth0=`ethtool eth0 | grep "Advertised auto-
negotiation"|awk -F': ''{if($2~/No/) print "Non-
negotiation."};{if($2~/Yes/) print "Negotiation"}'`
75.
76.Negotiation_eth1=`ethtool eth1 | grep "Advertised auto-
negotiation"|awk -F': ''{if($2~/No/) print "Non-
negotiation"};{if($2~/Yes/) print "Negotiation"}'`
77.
78.IP_eth0=`cat /etc/sysconfig/network-scripts/ifcfg-
eth0|grep IPADDR|awk -F= '{print $2}'`
79.
80.IP_eth1=`cat /etc/sysconfig/network-scripts/ifcfg-
eth1|grep IPADDR|awk -F= '{print $2}'`
81.
82.speed_eth0=`ethtool eth0|grep Speed|awk '{print $2}'`
83.speed_eth1=`ethtool eth1|grep Speed|awk '{print $2}'`
84.
85.echo "**********************************************"
86.echo "Network adapter info:"