检查Linux机器的内存使用状况之Shell脚本实现
2014-01-23 14:39
627 查看
#!/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
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有问必答:如何检查Linux的内存使用状况
- Linux使用expect脚本实现远程机器自动登录
- Linux使用Shell脚本实现ftp的自动上传下载
- 一个shell脚本实现linux集群所有机器免密钥登录
- Linux下使用Shell脚本实现ftp的自动上传下
- 【Shell脚本】统计本机内存情况和使用状况的脚本
- Linux使用Shell脚本实现ftp的自动上传下载
- Linux使用Shell脚本实现ftp的自动上传下载
- shell脚本监控linux系统内存使用情况的方法(不使用nagios监控linux)
- Linux使用Shell脚本实现ftp的自动上传下载(转)
- Linux上使用shell脚本查看内存情况(超实用)
- Linux使用Shell脚本实现ftp的自动上传下载
- Linux有问必答:如何检查Linux的内存使用状况
- Linux使用Shell脚本实现ftp的自动上传下载
- Linux下使用Shell脚本实现ftp的自动上传下载的代码小结 【转】
- linux脚本发送邮件 shell发送邮件(使用 msmtp+mutt+shell来实现)
- Linux下使用Shell脚本实现ftp的自动上传下载的代码小结
- Linux使用Shell脚本实现ftp的自动上传下载
- shell实现对机器内存和CPU使用情况的监控
- Linux使用Shell脚本实现ftp的自动上传下载