AI智能
改变未来

获取磁盘,内存,CPU使用情况的shell脚本


获取磁盘使用情况

#!/bin/bash# author: coco# date: 2020/07/03# usage: monitor memory statusDATE=$(date +\'%Y_%m_%d %H:%M:%S\')IPADDR=$(ifconfig | grep inet | awk \'NR==1{ print $2 }\')MAIL=\"[email protected]\"useRate=$(df -Th | awk \'{sum += $6} END {print sum}\')if [[ ${useRate} -ge 90 ]];thenecho \"Date: ${DATE}Host: ${HOSTNAME}: ${IPADDR}Problem:Memory using rate: up ${useRate}%\" | mail -s \"CPU Monitor Warnning\" ${MAIL}fi

获取内存的使用情况

#!/bin/bash# author: coco# date: 2020/07/03# usage: monitor memory statusDATE=$(date +\'%Y_%m_%d %H:%M:%S\')IPADDR=$(ifconfig | grep inet | awk \'NR==1{ print $2 }\')MAIL=\"[email protected]\"TOTAL=$(free -mw | awk \'NR==2{ print $2 }\')USE=$(free -mw | awk \'NR==2{ print $3 }\')FREE=$(free -mw | awk \'NR==2{ print $4 }\')CACHE=$(free -mw | awk \'NR==2{ print $7 }\')useRate=$(echo \"((${USE}+${CACHE})/${TOTAL})*100\" | bc -ql)freeRate=$(echo \"(${FREE}/${TOTAL})*100\" | bc -ql)if [[ ${FREE} -le 100 ]];thenecho \"Date: ${DATE}Host: ${HOSTNAME}: ${IPADDR}Problem:Memory using rate: ${useRate}%Memory free rate: ${freeRate}%\" | mail -s \"CPU Monitor Warnning\" ${MAIL}fi

获取CPU的使用情况

#!/bin/bash# author: coco# date: 2020/07/03# usage: monitor memory statusDATE=$(date +\'%Y_%m_%d %H:%M:%S\')IPADDR=$(ifconfig | grep inet | awk \'NR==1{ print $2 }\')MAIL=\"[email protected]\"ATE=$(date +\'%Y_%m_%d %H:%M:%S\')IPADDR=$(ifconfig | grep inet | awk \'NR==1{ print $2 }\')MAIL=\"[email protected]\"# 检测vmstat命令是否存在if ! which vmstat &>/dev/null; thenyum -y install procps-ng &>/dev/nullif [ $? -eq 0 ];thenecho \"vmstat already installed\"fifiUS=$(vmstat | awk \'NR==3{ print $13 }\')SY=$(vmstat | awk \'NR==3{ print $14 }\')ID=$(vmstat | awk \'NR==3{ print $15 }\')WA=$(vmstat | awk \'NR==3{ print $16 }\')ST=$(vmstat | awk \'NR==3{ print $17 }\')useTotal=$((${US}+${SY}))if [[ ${useTotal} -ge 70 ]];thenecho \"Date: ${DATE}Host: ${HOSTNAME}: ${IPADDR}Problem: CPU using rate: ${useTotal}%\" | mail -s \"CPU Monitor Warnning\" ${MAIL}fi
赞(0) 打赏
未经允许不得转载:爱站程序员基地 » 获取磁盘,内存,CPU使用情况的shell脚本