影黴:
#!/bin/bash
os_network(){
ip_addr=$(ifconfig ens33|awk '/broadcast/{print KaTeX parse error: Expected 'EOF', got '}' at position 2: 2}̲') echo…{ip_addr}"
##判断主机是否连接外网
ping -c1 www.baidu.com
if [ KaTeX parse error: Expected 'EOF', got '#' at position 73: …"服务器的网络未连接" fi #̲统计网卡(ens33)的流量 …(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 13: 5 /1024/1024}̲') echo "网卡流出的量…{TX}MB"
}
os_network
影黴:
#!/bin/bash
os_system(){
os_type=
(
u
n
a
m
e
)
e
c
h
o
"
操
作
系
统
的
类
型
:
(uname) echo "操作系统的类型:
(uname)echo"操作系统的类型:{os_tyoe}"
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}"
#修改主机名称
#hostname set-hostname 1712A
}
os_system
影黴:
men_info(){
#内存总大小
men_total=$(free -m|sed -n “2p”|awk '{print KaTeX parse error: Expected 'EOF', got '}' at position 2: 2}̲') echo…{men_total}"
#已使用的内存
men_used=$(free -m|sed -n “2p”|awk '{print KaTeX parse error: Expected 'EOF', got '}' at position 2: 3}̲') echo…{mem_used}"
#剩余内存总量
men_free=$(free -m|sed -n “2p”|awk '{print KaTeX parse error: Expected 'EOF', got '}' at position 2: 4}̲') echo…{men_free}"
#已使用内存百分比
#
m
e
n
u
s
e
d
/
{men_used}/
menused/{mem_total}
percent_mem_used=
(
e
c
h
o
"
s
c
a
l
e
=
2
;
(echo "scale=2;
(echo"scale=2;{men_used}/
m
e
n
t
o
t
a
l
∗
100
"
∣
b
c
)
e
c
h
o
"
已
使
用
内
存
百
分
比
:
{men_total}*100"|bc) echo "已使用内存百分比:
mentotal∗100"∣bc)echo"已使用内存百分比:{percent_men_used}"
#剩余内存百分比
#
m
e
m
f
r
e
e
/
{mem_free}/
memfree/{men_total}
percent_mem_free=
(
e
c
h
o
"
s
c
a
l
e
=
2
;
(echo "scale=2;
(echo"scale=2;{mem_free}/%{mem_total}*100"|bc)
echo “剩余内纯百分比:${percent_men_free}”
}
men_info