如上的内存利用率 = 【-/+buffers/cache:used】/【Mem:total 】 =  6293404 / 16333656

对于free命令而言,有如下公式:

  total = used + free;

  (-buffers/cache) used = Mem:used - Mem:buffers -
Mem:cached;

  (-buffers/cache) used= ( Mem:total - Mem:free ) -  Mem:buffers -
Mem:cached

  (+buffers/cache) free = Mem:free + Mem:buffers + Mem:cached

因此:(-buffers/cache) used内存数:6293404 = 真实内存占用

而+buffers/cache反映的是可以挪用的内存总数,并非目前真真正正使用的内存。

#!/bin/bash

#test_MemoryUsageShell

while :
do
phymem=`free | grep "Mem:" |awk '{print $2}'`
phymemused=`free | grep 'buffers/cache' | awk '{print $3}'` # echo $phymem
# echo $phymemused awk 'BEGIN{printf"%.2f%\n",('$phymemused'/'$phymem')*100}' sleep 3 done

  

linux上使用shell脚本查看内存使用率的更多相关文章

  1. Linux上使用shell脚本查看内存情况(超实用)

    #!/bin/bashexport chknum=1 #shell搅拌存放目录(输出日志文件执行后也存于该目录)echo 3 > /wls/wls81/shellsyncwhile [ $chk ...

  2. linux 执行远程linux上的shell脚本或者命令以及scp 上传文件到ftp--免密码登陆

    场景:在linux A 上执行Linux B上的shell脚本和命令 步骤1.设置ssh免登陆 1.SSH无密码登录 # 本地服务器执行(A机器):生成密钥对 ssh-keygen -t dsa -P ...

  3. Linux上定时shell脚本

    原文链接:http://www.92coder.com/9-Linux%E5%AE%9A%E6%97%B6shell%E8%84%9A%E6%9C%AC/#more 本文主要介绍在Linux系统上部署 ...

  4. shell脚本-巡检内存使用率

    #!/bin/bash # by dreamer Q # 巡检内存脚本 #总内存大小 mem_total=`free -m | sed -n '2p' |awk '{print $2}'` #已使用内 ...

  5. Java 连接远程Linux 服务器执行 shell 脚本查看 CPU、内存、硬盘信息

    pom.xml jar 包支持 <dependency> <groupId>com.jcraft</groupId> <artifactId>jsch& ...

  6. Shell脚本查看linux系统性能瓶颈(转)

    Shell脚本查看linux系统性能瓶颈(转自:http://blog.51cto.com/lizhenliang/1687612) [root@test ~]# cat show_sys_info. ...

  7. Linux下添加shell脚本使得nginx日志每天定时切割压缩

    Linux下添加shell脚本使得nginx日志每天定时切割压缩一 简介 对于nginx的日志文件,特别是access日志,如果我们不做任何处理的话,最后这个文件将会变得非常庞大 这时,无论是出现异常 ...

  8. mac链接linux终端,shell脚本发布代码

    项目的业务需求:从mac端直接连上linux服务终端,并发布相关的代码 一.使用ssh链接上linux服务端 1.cd ~/.ssh 2.vi config,按照下面的内容配置config文件,然后: ...

  9. windows下上传shell脚本不能运行—将dos模式修改为unix 文件格式

    windows下上传shell脚本至linux,其格式将为dos.dos模式的shell脚本将不能再linux下正确运行,需要修改文件模式为unix. 1 查看文件模式方法 linux服务器上,用vi ...

随机推荐

  1. [已解决] github merge指定commit

    比如说有两个branch,分别是master和m1,我们在m1上修改的bug怎么merge到master上呢, 怎么merge我不知道,但是有另外一个命令可以做到,比如m1做commit,sha-1为 ...

  2. Java中excute,excuteUpdate,excuteQuery的区别

    executeQuery(String sql)      执行select语句,它返回的是查询后得到记录集(resultset). executeUpdate(String sql)      执行 ...

  3. 中文 iOS/Mac 开发博客列表(转)

    转自https://github.com/tangqiaoboy/iOSBlogCN 中文 iOS/Mac 开发博客列表 本博客列表会不断更新维护,如果有推荐的博客,请到此处提交博客信息. 本博客列表 ...

  4. Windows使用shipyard

    步骤: 1. 安装go语言环境,配置go语言环境变量 如果是64位,GOARCH=amd64 http://my.oschina.net/pandao/blog/161667 2. 找一台linux或 ...

  5. Boost学习笔记(五) progress_display

    progress_display可以在控制台显示程序的执行进度,如果程序执行很耗费时间,那么它能够提供一个友好的用户界面 #include <boost\timer.hpp> #inclu ...

  6. juqery模板 Templates

    现在已经有了许多JavaScript的解决方案模板,从这方面说,标准化的模板解决方案必然是大势所趋.在本节中,我们向你简要描述四个最流行最有趣的模板.现有的模板解决方案能解决什么?那些特色在jQuer ...

  7. Object-C

    #import <Foundation/Foundation.h> #pragma mark 狗类的声明 @interface Dog:NSObject { @public NSStrin ...

  8. fzu1036四塔问题(汉诺塔问题拓展)

    #include<iostream> #include<cstdio> #include<cmath> using namespace std; ]; int ru ...

  9. EJB的调用

    EJB调用.html :first-child{margin-top:0!important}img.plugin{box-shadow:0 1px 3px rgba(0,0,0,.1);border ...

  10. spring 注解重复(防重复请求)

    1.配置拦截器 spring-mvc.xml <mvc:interceptors> <mvc:interceptor> <mvc:mapping path="/ ...