赞
踩
#!/bin/bash function os_sys() { #系统信息 os_type=$(uname) os_version=$(cat /etc/redhat-release) os_ker=$(uname -r) os_time=$(date +%F_%T) os_last_reboot=$(uptime |awk '{print $3,$4}'| awk -F ',' '{print $1}') os_hostname=$(hostname) echo "#操作系统的类型:" "${os_type}" echo "#操作系统的版本号:" "${os_version}" echo "#操作系统的内核版本:" "${os_ker}" echo "#服务器当前的运行时间:" "${os_time}" echo "#服务器最后重启时间:" "${os_last_reboot}" echo "#服务器的主机名:" "${os_hostname}" } function os_network() { #网络信息 ip_addr=$(ifconfig ens33 |awk '/netmask/{print $2}') echo "服务器的IP地址为:${ip_addr}" ping -c2 www.baidu.com > /dev/null if [ $? -eq 0 ];then echo "服务器的网络正常" else echo "数据异常请检查网路" fi RX=$(ifconfig ens33 | grep RX | sed -n '1p' | awk '{print $(NF-1),$NF}') TX=$(ifconfig ens33 | grep TX | sed -n '1p' | awk '{print $(NF-1),$NF}') echo "网卡流入的量为:${RX}" echo "网卡流出的量为:${TX}" echo " " } function cpu_info() { #cpu cpu_num=$(cat /proc/cpuinfo |grep "physical id" | sort |uniq |wc -l) cpu_core=$(cat /proc/cpuinfo |grep "core id" |sort |uniq |wc -l) cpu_model=$(cat /proc/cpuinfo |grep "model name" |uniq |awk '{print $4,$6,$7,$9}') echo "cpu的物理个数为:${cpu_num}" echo "cpu的核心个数为:${cpu_core}" echo "cpu的型号:${cpu_model}" echo " " } #mem function mem_info() { #内存总大小 mem_total=$(free |awk '/Mem/{print $2}') #已使用内存 mem_used=$(free |awk '/Mem/{print $3}') #剩余内存大小 mem_free=$(free |awk '/Mem/{print $4}') #已使用内存百分比 p_bfb=$(free |awk '/Mem/{printf "%.2f\n",$3/$2*100}') #剩余内存百分比 s_bfb=$(free |awk '/Mem/{printf "%.2f\n",$4/$2*100}') echo "内存总大小: ${mem_total}" echo "已用内存大小:${mem_used}" echo "剩余内存大小:${mem_free}" echo "已使用内存百分比:${p_bfb}%" echo "剩余内存百分比:${s_bfb}%" echo " " } function disk_info() { #disk #磁盘总量 disk_total=$(lsblk |awk '/disk/{print $4}') count=($(df -Tm |egrep -v tmpfs |sed '1d' |awk '{print $5}')) sum=0 for i in ${count[@]} do let sum=sum+"${i}" done sumb=("${sum}"/1024) echo " 磁盘总量为:${disk_total}" echo "剩余磁盘总量为 $sum M" } function main() { os_sys os_network cpu_info mem_info disk_info } #while : #do main #slepp 5 #done
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。