第三个shell脚本

该脚本通过命令查看内存的频率、最大内存、内存插槽数量、CPU型号、主板型号等参数。

#!/bin/bash
#who is this?
[ ${UID} -ne 0 ] && (echo "must is root";exit 1)
#View memory frequency
/usr/sbin/dmidecode|awk '$1~/Speed/&& $2~/[0-9][0-9]/{print "Memory Frequency:",$2}'|uniq

#View maximum supported memory
/usr/sbin/dmidecode|awk '/Maximum Capacity/{print }'|sed 's/^.//g'

#View number of memory slots
/usr/sbin/dmidecode|awk '$1~/Size/{print|"wc -l"}'|awk '{print "Number of memory slots:",$1}'

#View maximum memory
/usr/sbin/dmidecode|grep -P -A5 "Memory\s+Device"|grep Size|egrep -v 'Range|No'|uniq|awk '{print "Single memory:",$2,$3}'

#View Number of cpu cores
cat /proc/cpuinfo|awk '$1=="processor"{print|"wc -l"}'|awk '{print "Number of cpu cores:",$1}'

#Cpu model
cat /proc/cpuinfo|grep 'model name'|uniq|cut -d":" -f2|awk '{print "Cpu model:",$0}'

#View HDD or SSD
df -h|grep '^/dev'|awk '{print "hard disk space",$2,$4,$6}'

#View Motherboard model
/usr/sbin/dmidecode|grep 'Product Name'|awk '$3!="System"{print "Motherboard model:" $3,$4,$5,$6,$7}'

执行脚本输出如下:
Memory Frequency: 1333 #内存频率
Maximum Capacity: 8 GB #最大内存支持
Number of memory slots: 2 #内存槽数量
Single memory: 4096 MB #单根插槽支持多大内存
Number of cpu cores: 4 #CPU核心数量
Cpu model: AMD Athlon(tm) II X4 640 Processor #CPU型号
hard disk space 108G 32G / #磁盘分区信息
hard disk space 297M 16M /boot #磁盘分区信息
Motherboard model:M5A78L-M LX #主板型号

通过awk命令应该可以更好的处理以上信息,但不知道语法怎么写,awk感觉好复杂,如果要远程执行的话可以通过
ssh root@xxxxxx < 脚本名称 来执行

转载于:https://blog.51cto.com/pkimin3/2391813

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值