1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
| #!/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" ];then
echo"This script must be executed as root"
exit 1
fi
# Display an error and exit
errorExit() {
echo"$@" >&2
exit 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=0
count=`dmidecode | grep -A4 "BIOS NIC"|sed -e '1d' | wc -l`
if [ -f "/tmp/speed.txt" ];then
rm -rf /tmp/speed.txt
fi
while [[${i} -lt ${count} ]]
do
ethtool eth"${i}"|grep "Speed:" >> /tmp/speed.txt
let "i++"
done
dmidecode| 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.txt
paste /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!"
|