os_check(){
os_type=$(uname -r)
echo "系统类型为:${os_type}"
os_version=$(cat /etc/redhat-release)
echo "系统版本号为:${os_version}"
os_ker=$(uname -a|awk '{print $3}')
echo "系统内核信息为:${os_ker}"
os_date=$(date +%F_%T)
echo "当前时间为:${os_date}"
os_run_time=$(uptime |awk '{print $1,$3}'|awk -F ',' '{print $1}')
echo "系统运行时间:${os_run_time}"
os_last_reboot=$(who -b|awk '{print $2,$3}')
echo "系统最后重启时间:${os_last_reboot}"
os_hostname=$(hostname)
echo "服务器的主机名为:${os_hostname}"
}
network_check(){
ip_addr=$(ifconfig ens33|awk '/broadcast/ {print $2}')
echo "服务器的ip地址为:${ip_addr}"
ping -c 3 www.baidu.com >/dev/null
if [ $? -eq 0 ]; then
echo "network is ok"
else
echo "not ok,please check network!"
fi
}
cpu_check(){
cpu_physical=$(cat /proc/cpuinfo |grep "physical id"|sort |uniq |wc -l)
echo "cpu的物理个数:${cpu_physical}"
cpu_core=$(cat /proc/cpuinfo |grep "core id"|sort |uniq |wc -l)
echo "cpu的核心数:${cpu_core}"
cpu_model=$(cat /proc/cpuinfo |grep "model name"|sort |uniq |awk -F ':' '{print $2}')
echo "cpu的型号信息:${cpu_model}"
}
mem_check(){
mem_total=$(free -m|awk '/Mem/ {print $2}')
echo "内存总量为:${mem_total}"
mem_free=$(free -m|awk '/Mem/ {print $4}')
echo "内存剩余总量为:${mem_free}"
}
disk_check(){
disk_total=$(lsblk |awk '/disk/{print $4}')
echo "磁盘总量为:${disk_total}"
shuzu=(`df -T|grep -v "tmpfs"|sed '1d'|awk '{print $5}'`)
diskfree=0
for ((i=0;i<`echo ${
do
diskfree=`expr $diskfree + ${shuzu[$i]}`
done
echo "磁盘剩余总量为:$diskfree"
}
while true
do
os_check
network_check`在这里插入代码片`
cpu_check
mem_check
disk_check
sleep 2
done
[root@localhost shell]
系统类型为:3.10.0-1062.el7.x86_64
系统版本号为:CentOS Linux release 7.7.1908 (Core)
系统内核信息为:3.10.0-1062.el7.x86_64
当前时间为:2020-04-20_17:15:57
系统运行时间:17:15:57 8:01
系统最后重启时间:2020-03-08 22:22
服务器的主机名为:localhost.localdomain
服务器的ip地址为:192.168.44.179
network is ok
cpu的物理个数:1
cpu的核心数:1
cpu的型号信息: Intel(R) Core(TM) i7-7700HQ CPU @ 2.80GHz
内存总量为:1819
内存剩余总量为:148
磁盘总量为:20G
磁盘剩余总量为:13747212