1、为了方便查询服务器的硬件信息,将需要查询的内容整理成Shell脚本,输出自己想要的格式。其实就是通过dmidecode命令输出,然后通过sed,awk,cut命令的处理。

2、此脚步适用于HP DL系列的服务器,Dell PowerEdge系列的会有少许内容不同,所以在抓取过程会有小小报错。

3、脚本内容如下:

#!/bin/bash
############################################################################
# Check the server hardware configuration
#
# History: 2016/04/16 zhuwei First release
############################################################################# set a safe path before doing anything else
PATH=/sbin:/usr/sbin:/bin:/usr/bin; export PATH# This script must be executed as root
RUID=`/usr/bin/id|awk -F\( '{print $1}'|awk -F\='{print $2}'`
# #OR# RUID=`id | cut -d\( -f1 | cut -d\= -f2` #OR#ROOT_UID=0
if [ ${RUID} != "0" ];thenecho"This script must be executed as root"exit 1
fi# Display an error and exit
errorExit() {echo"$@" >&2exit 1
}# Display the normal print
display() {echo -e"\033[32m***********************************************************\
******************************\033[0m"echo -e"\033[32m*\033[0m"$@""echo -e"\033[32m***********************************************************\
******************************\033[0m"
}#Check the server model, serial number
model() {dmidecode|grep "System Information" -A9|egrep"Manufacturer|Product|Serial" \| awk 'BEGIN {FS="\n";RS=""} {print $1,$2,$3}' | sed 's/^[\t]//g'
}
#Query cpu Information
cpu(){dmidecode| grep -A55 "Processor Information" | \egrep "Version:|Core Count:|Thread Count:"|sed -e 's/^[\t]//' \-e'/Version:/i\\' | sed '1d' | awk 'BEGIN {FS="\n";RS=""}{print $1,$2,"\t"$3}'\| sed's/Version://'
}
#Query memory Information
memory(){dmidecode| grep -A12 "Memory Device"|egrep "Type:|Size|Speed:|Locator:P" \| sed -n -e '/MB/,/MHz/p' | sed '/Size:/i\\' | sed -e '1d' -e 's/^[\t]*//' \| awk'BEGIN {FS="\n";RS=""} {print $2} {print"\t"$3,"\t"$1,"\t"$4}'#sed'/Size:/i\\' | sed -e '1d' -e 's/^[\t]*//' #replaced##awk'BEGIN {FS="\n"}{if(NR%4==1){print "\n"}{print $1}}' | sed's/^[\t]*//'
}
#Query Network Information
network(){i=0count=`dmidecode | grep -A4 "BIOS NIC"|sed -e '1d' | wc -l`if [ -f "/tmp/speed.txt" ];thenrm -rf /tmp/speed.txtfiwhile [[${i} -lt ${count} ]]doethtool eth"${i}"|grep "Speed:" >> /tmp/speed.txtlet "i++"donedmidecode| grep -A4 "BIOS NIC"|sed -e '1d' -e 's/^[\t]//'| cut -d, -f2 | \awk  'FNR==0 {print "\r\n" FILENAME}{print et NR-1 "\t" $0}' \et="eth" > /tmp/network.txtpaste /tmp/network.txt /tmp/speed.txt
}display "System Information:" && model || errorExit "This command is error!"
display "CPU Information:" && cpu|| errorExit "This command is error!"
display "Memory Information:" && memory || errorExit "This command is error!"
display "Network Information:" && network || errorExit "This command is error!"

4、这里只对服务器厂商,内存,CPU配置和网卡信息,对于硬盘信息可根据不同厂商的管理工具来获取。HP使用hp-health-*rpm,G9版本以上使用hpssacli-*.rpm,安装以后使用:hpacucli ctrl all show config 查看RAID信息。Dell安装Dell OpenManage Server Administrator工具查看,通过命令:omreport storage pdisk controller=0来查看。

5、查看RAID信息还可以使用MegaCli开源工具进行查看,这里不作介绍。

转载于:https://blog.51cto.com/wyzwl/1765386

使用Shell脚本查询服务器硬件信息相关推荐

  1. crontab里shell脚本将top信息写入文件

    crontab里shell脚本将top信息写入文件: 注: 1.top -n 1代表执行1次退出(默认top是不退出的),-d 1代表每1秒执行1次 2.crontab里需加/bin/bash # c ...

  2. Shell脚本 – 查看网络接口信息

    转载来源 :Shell脚本 – 查看网络接口信息 https://mp.weixin.qq.com/s/qdEzm-GcoFYvC50XWfchrQ 本文介绍如何是用shell脚本查看网络接口的ip地 ...

  3. linux实现学生信息管理系统,Linux下基于shell脚本实现学生信息管理系统

    LINUX Linux操作系统 Linux下基于shell脚本实现学生信息管理系统 #该管理系统是参考两位博主(时间有点远了,我忘了,请博主看到后联系我)后自行修改添加的.登录过程还有很多不完善,我就 ...

  4. shell脚本查询mysql

    接到统计需求,需要对一批对一批uid过滤,只保留10月1日之后注册的uid,用户注册时间可以从mysql里面拿,写了个shell脚本 ps:用户信息使用十库十表存储,像 12345这个uid存储在5这 ...

  5. linux shell 和 golang 查询服务器硬件信息

    dmidecode 是一个读取电脑 DMI(桌面管理接口(Desktop Management Interface))表内容并且以人类可读的格式显示系统硬件信息的工具.(也有人说是读取 SMBIOS ...

  6. shell脚本 系统状态信息查看

    一.简介 介绍:显示简单的系统信息 效果图: 二.使用 适用:centos6.7+,ubuntu12+ 语言:中文 注意:先在测试机实验一下 下载地址: http://wget.52liangzy.t ...

  7. shell监控java接口服务_Linux系统下Java通过shell脚本监控重启服务

    简介 最近运维人员提出需求,增加一个运维页面, 查询当前的业务进程信息包括:进程名称.启动命令.启动时间.运行时间等,可以通过页面点击重启按钮,可以重启后端的一系列系统进程. 思路 java程序获取l ...

  8. Android:JNI与NDK(四) Shell脚本的学习以及交叉编译libjpeg图片处理库

    本篇目录 一.前言 首先,向关注公众号的朋友们道个歉,很长时间没更新了,实在惭愧,这段时间忙于个人事务,耽误了很长时间. 各位小伙伴们可以关注一下我的个人github地址:https://github ...

  9. 用 Shell 脚本访问 MySQL 数据库

    下午写了一个简单的 bash 脚本,用来测试程序,输入一个测试用例文件,输出没有通过测试的用例和结果,然后把结果保存到数据库里.如何在 bash 脚本里直接访问数据库呢?既然在 shell 里可以直接 ...

最新文章

  1. iPhone 用户请注意:你的邮件 App 得禁用,刚曝光的安全漏洞,iOS 6 以上设备全中招...
  2. 牛客练习赛61 E 相似的子串(二分+哈希)难度⭐⭐⭐
  3. Leetcode 166. 分数到小数 解题思路及C++实现
  4. Python基础笔记8
  5. 发送JSON数据给服务器
  6. 封装js千分位加逗号和删除逗号
  7. JAVA单向链表实现
  8. poj 1274 The Perfect Stall
  9. 类与对象和对应方法、封装
  10. ios 请求失败封装_vue_axios请求封装、异常拦截统一处理
  11. Atitit 面向对象编程(OOP)、面向组件编程(COP)、面向方面编程(AOP)和面向服务编程(SOP)的区别和联系...
  12. “要么你去驾驭生命,要么生命驾驭你。你的心态决定谁是坐骑,谁是骑师。”...
  13. 清空linux+history_1分钟学会的Linux小技巧,大大提高你的工作效率
  14. RankLib参数翻译
  15. 阶段3 1.Mybatis_01.Mybatis课程介绍及环境搭建_03.jdbc操作数据库的问题分析
  16. 网上很多NV21数据直接使用BitmapFactory的代码是错误的
  17. JavaWeb源码网上商城系统a
  18. Easy RM to MP3 Converter漏洞分析报告
  19. 无法定位程序输入点于动态链接库上的解决方法分享
  20. ICP经营许可证需要多久能够下证

热门文章

  1. OpenCV学习——形态学
  2. 相机矩阵(Camera Matrix)
  3. python面向对象三大特性、类的约束、print带颜色输出及super补充
  4. [BZOJ]3173: [Tjoi2013]最长上升子序列
  5. BZOJ3555: [Ctsc2014]企鹅QQ
  6. 6.2 常见多媒体标准及压缩技术
  7. ADO.NET改进防注入
  8. hdu 5813 Elegant Construction
  9. [摘抄]MySQL数据库系统的常规管理介绍
  10. Jquery中post与get之间的区别详细介绍