shell 脚本监控linux

匿名 (未验证) 提交于 2019-12-02 21:56:30
[root@dn3 data]# cat monitor.sh  #!/bin/bash cpu_idle=$(top -n2|grep 'Cpu'|tail -n 1|awk '{print $8}') cpu_usage=$(echo "100 - $cpu_idle"|bc|awk '{printf "%.2f", $0}') echo "CPU利用率:$cpu_usage %"  mem_free=$(free -m|awk '/Mem:/{print $4 + $6 + $7}') mem_total=$(free -m|awk '/Mem:/{print $2}') mem_used=$(echo "$mem_total-$mem_free"|bc) mem_used_rate=$(echo "$mem_used * 100 / $mem_total"|bc) echo "内存使用量:$mem_used M" echo "内存使用率:$mem_used_rate %"  disk_used=$(df -h /|tail -n 1|awk '{print $3}') disk_use=$(df -h /|tail -n 1|awk '{print $5}') echo "磁盘空间使用量:$disk_used" echo "磁盘空间使用率:$disk_use"

执行脚本,可以得到系统的监控信息。

[root@dn3 data]# sh monitor.sh  CPU利用率:0.70 % 内存使用量:1317 M 内存使用率:71 % 磁盘空间使用量:4.8G 磁盘空间使用率:6%

 

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!