检查Linux机器的内存使用状况之Shell脚本实现

#!/bin/bash
export chknum=1
echo 3 > /proc/sys/vm/drop_caches
sync
while [ $chknum -ge 0 ]
do
echo "-------------------------------------------------------" >> trace.log
mt=`free | tr [:blank:] \\\n | grep [0-9] | sed -n ‘1p‘`
mu=`free | tr [:blank:] \\\n | grep [0-9] | sed -n ‘2p‘`
mf=`free | tr [:blank:] \\\n | grep [0-9] | sed -n ‘3p‘`
st=`free | tr [:blank:] \\\n | grep [0-9] | sed -n ‘9p‘`
su=`free | tr [:blank:] \\\n | grep [0-9] | sed -n ‘10p‘`
sf=`free | tr [:blank:] \\\n | grep [0-9] | sed -n ‘11p‘`
t=`expr $mt + $st`
u=`expr $mu + $su`
echo "Total Mem: $t"
echo "Used Mem: $u"
R=`expr $mu \* 100 / $mt`
echo "当前内存使用率为: $R%" >>trace.log
echo "$R" >> memory.log
echo "记录时间:" >> trace.log
echo `date` >> trace.log
echo "-------------------------------------------------------" >> trace.log
sleep 20
done

检查Linux机器的内存使用状况之Shell脚本实现

上一篇:android studio Warehouse(仓库配置)


下一篇:01_uni-app中vue组件父子值传递