/etc/mail.rc"/>
您好,登錄后才能下訂單哦!
#!/bin/bash
#觸發(fā)閾值發(fā)郵件還沒有寫.
export PATH
export LANG=zh_CN.UTF-8
#先配置好mailx郵箱賬號(hào)密碼:
#cat>/etc/mail.rc<<"EOF"
#set sendcharsets=iso-8859-1,utf-8
#set from=xxx@163.com
#set smtp=smtp.163.com
#set smtp-auth-user=xx@163.com
#set smtp-auth-password=xxx
#set smtp-auth=login
#EOF
readonly times=$(date +%Y"/"%m"/"%d" "%k":"%M)
readonly machine="192.168.1.10"
function top_check(){
runup=$(top -n 1|grep user|awk -F '[, ]+' '{print $5}')
echo "$times $machine 運(yùn)行多久: $runup 分鐘"
userd=$(top -n 1|grep user|awk -F '[, ]+' '{print $7}')
echo "$times $machine 當(dāng)前在線用戶數(shù): $userd"
load1=$(top -n 1|grep user|awk -F '[, ]+' '{print $11}')
echo "$times $machine 1分鐘CPU負(fù)載: $load1"
load5=$(top -n 1|grep user|awk -F '[, ]+' '{print $12}')
echo "$times $machine 5分鐘CPU負(fù)載: $load5"
load15=$(top -b -n 1|grep user|awk '{print $NF}')
echo "$times $machine 15分鐘CPU負(fù)載: $load15"
cpuus=$(top -n 1|grep Cpu|awk -F "," '{print $1}'|awk -F " " '{print $2}')
echo "$times $machine 用戶空間占用CPU百分比: $cpuus"
cpusy=$(top -n 1|grep Cpu|awk -F "," '{print $2}'|awk -F " " '{print $2}')
echo "$times $machine 內(nèi)核空間占用CPU百分比: $cpusy"
cpuni=$(top -n 1|grep Cpu|awk -F "," '{print $3}'|awk -F " " '{print $2}')
echo "$times $machine 改變過優(yōu)先級(jí)的進(jìn)程占用CPU的百分比: $cpuni"
cpuid=$(top -n 1|grep Cpu|awk -F "," '{print $4}'|awk -F " " '{print $2}')
echo "$times $machine 空閑CPU百分比: $cpuid"
cpuwa=$(top -n 1|grep Cpu|awk -F "," '{print $5}'|awk -F " " '{print $2}')
echo "$times $machine I/O等待占用CPU的百分比: $cpuwa"
cpuhi=$(top -n 1|grep Cpu|awk -F "," '{print $6}'|awk -F " " '{print $2}')
echo "$times $machine 硬中斷占用CPU的百分比: $cpuhi"
cpusi=$(top -n 1|grep Cpu|awk -F "," '{print $7}'|awk -F " " '{print $2}')
echo "$times $machine 軟中斷占用CPU的百分比: $cpusi"
cpust=$(top -n 1|grep Cpu|awk -F "," '{print $8}'|awk -F " " '{print $2}')
echo "$times $machine 虛擬 CPU 等待實(shí)際 CPU 的時(shí)間的百分比: $cpust"
#內(nèi)存部分M為單位
memtotal=$(($(top -n 1|grep buff/cache|awk -F '[, ]+' '{print $4}') / 1024))
echo "$times $machine 內(nèi)存總共: $memtotal M"
memfree=$(($(top -n 1|grep buff/cache|awk -F '[, ]+' '{print $7}') / 1024))
echo "$times $machine 空閑內(nèi)存: $memfree M"
memused=$(($(top -n 1|grep buff/cache|awk -F '[, ]+' '{print $10}') / 1024))
echo "$times $machine 已使用內(nèi)存: $memused M"
membuff=$(($(top -n 1|grep buff/cache|awk -F '[, ]+' '{print $13}') / 1024))
echo "$times $machine 內(nèi)存buff/cache: $membuff M"
#swap部分M
swaptotal=$(($(top -n 1|grep avail|awk -F '[, ]+' '{print $3}') / 1024))
echo "$times $machine swap總共: $swaptotal M"
swapfree=$(($(top -n 1|grep avail|awk -F '[, ]+' '{print $6}') / 1024))
echo "$times $machine swap空閑: $swaptotal M"
swapused=$(($(top -n 1|grep avail|awk -F '[, ]+' '{print $9}') / 1024))
echo "$times $machine swap已使用: $swapused M"
swapavail=$(($(top -n 1|grep avail|awk -F '[, ]+' '{print $11}') / 1024))
echo "$times $machine swap內(nèi)存avail Mem: $swapavail M"
}
files="/tmp/top.logs"
top_check >$files
dos2unix -k $files
mailx -s "$machine" xxx@vip.qq.com < $files
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。