#!/bin/bash
os_system(){
##系统信息
os_type=
(
u
n
a
m
e
)
e
c
h
o
"
操
作
系
统
的
类
型
:
(uname) echo "操作系统的类型 :
(uname)echo"操作系统的类型:{os_type}"
##系统信息
os_ver=
(
c
a
t
/
e
t
c
/
r
e
d
h
a
t
−
r
e
l
e
a
s
e
)
e
c
h
o
"
操
作
系
统
的
类
型
:
(cat /etc/redhat-release) echo "操作系统的类型 :
(cat/etc/redhat−release)echo"操作系统的类型:{os_ver}"
os_ker= ( u n a m e − r ) e c h o " 操 作 系 统 的 版 本 信 息 : (uname -r) echo "操作系统的版本信息 : (uname−r)echo"操作系统的版本信息:{os_ker}"
os_time= ( d a t e + e c h o " 服 务 器 当 前 时 间 : (date +%F_%T) echo "服务器当前时间: (date+echo"服务器当前时间:{os_time}"
os_last_reboot=$(uptime |awk ‘{print $3,$4}’|awk -F ‘,’ '{print KaTeX parse error: Expected 'EOF', got '}' at position 2: 1}̲') echo "服务器最后重…{os_last_reboot}"
os_hostname=
(
h
o
s
t
n
a
m
e
)
e
c
h
o
"
服
务
器
主
机
名
称
:
(hostname) echo "服务器主机名称:
(hostname)echo"服务器主机名称:{os_hostname}"
}
os_network(){
##网络信息
##主机的ip地址
##yum -y install net-tools
ip_addr=$(ifconfig ens33|awk ‘/broadcast/{print $2}’)
echo “服务器的ip地址为:${ip_addr}”
##判断主机是否可以联通外网
ping -c1 www.qq.com
if [ $? -eq 0 ];then
echo “服务器网络是ok”
else
echo “服务器网络 不ok”
fi
##统计网卡ens33的流量
##流入流量
RX=$(ifconfig ens33|grep RX|sed -n ‘1p’|awk '{print KaTeX parse error: Expected 'EOF', got '}' at position 12: 5/1024/1024}̲') echo "网卡流入流量{RX}MB"
##流出流量
TX=$(ifconfig ens33|grep TX|head -n1|awk '{print KaTeX parse error: Expected 'EOF', got '}' at position 12: 5/1024/1024}̲') echo "网卡流chu…{TX}MB"
}
cpu_info(){
#cpu的物理个数
cpu_phy=
(
c
a
t
/
p
r
o
c
/
c
p
u
i
n
f
o
∣
g
r
e
p
"
p
h
y
s
i
c
a
l
i
d
"
∣
s
o
r
t
∣
u
n
i
q
∣
w
c
−
l
)
e
c
h
o
"
c
p
u
物
理
个
数
为
:
(cat /proc/cpuinfo |grep "physical id"|sort |uniq |wc -l) echo "cpu物理个数为:
(cat/proc/cpuinfo∣grep"physicalid"∣sort∣uniq∣wc−l)echo"cpu物理个数为:{cpu_phy}"
##cpu的核心数
cpu_core=$(cat /proc/cpuinfo |grep “cores id”|sort |uniq |wc -l)
echo "cpu的核心 KaTeX parse error: Expected 'EOF', got '#' at position 13: {cpu_core}" #̲#cpu的型号 cpu_mod…(cat /proc/cpuinfo |grep “model name”|sort |uniq |awk -F ‘:’ ‘{print $2}’)
echo “cpu的型号 KaTeX parse error: Expected 'EOF', got '}' at position 14: {cpu_model}" }̲ mem_info(){ …(free -m| sed -n “2p”|awk '{print KaTeX parse error: Expected 'EOF', got '}' at position 2: 2}̲') echo…{mem_total}”
#已使用的内存
mem_used=$(free -m| sed -n "2p"|awk '{print $3}')
echo "已使用的内存:${mem_used}"
#剩余内存总量
mem_free=$(free -m| sed -n "2p"|awk '{print $4}')
echo "剩余内存总量:${mem_free}"
}
while :
do
os_system
os_network
cpu_info
mem_info
done