shell脚本中变量的递归使用--真实内存使用查看脚本
2017-09-05 14:04
477 查看
脚本中进行变量计算时,需要加一个[ ],在外面再套一个$
[root@ES25 tmp]# cat real_mem_used01.sh
#!/bin/bash
TOTAL=`free -g|grep Mem |awk '{print $2}'`
USED=`free -g|grep Mem |awk '{print $3}'`
BUFFER=`free -g|grep Mem |awk '{print $6}'`
CACHE=`free -g|grep Mem |awk '{print $7}'`
real_used=$[$USED - $BUFFER - $CACHE]
PUSED=$[$real_used*100/$TOTAL]
echo $PUSED%
[root@ES25 tmp]#
[root@ES25 tmp]# sh real_mem_used01.sh
12%
[root@ES25 tmp]#
方法二:
[root@ES25 tmp]# cat aa.sh
#!/bin/bash
Real_used=`free -g|grep cache |grep ":"|awk '{print $3}'`
Total=`free -g|grep Mem|awk '{print $2}'`
awk 'BEGIN{printf"%.2f\n",('$Real_used'/'$Total')*100}'
[root@ES25 tmp]# sh aa.sh
10.64
[root@ES25 tmp]#
[root@ES25 tmp]# cat real_mem_used01.sh
#!/bin/bash
TOTAL=`free -g|grep Mem |awk '{print $2}'`
USED=`free -g|grep Mem |awk '{print $3}'`
BUFFER=`free -g|grep Mem |awk '{print $6}'`
CACHE=`free -g|grep Mem |awk '{print $7}'`
real_used=$[$USED - $BUFFER - $CACHE]
PUSED=$[$real_used*100/$TOTAL]
echo $PUSED%
[root@ES25 tmp]#
[root@ES25 tmp]# sh real_mem_used01.sh
12%
[root@ES25 tmp]#
方法二:
[root@ES25 tmp]# cat aa.sh
#!/bin/bash
Real_used=`free -g|grep cache |grep ":"|awk '{print $3}'`
Total=`free -g|grep Mem|awk '{print $2}'`
awk 'BEGIN{printf"%.2f\n",('$Real_used'/'$Total')*100}'
[root@ES25 tmp]# sh aa.sh
10.64
[root@ES25 tmp]#
相关文章推荐
- Linux上使用shell脚本查看内存情况(超实用)
- Shell脚本查看进程内存真实占用情况
- 用来查看linux内存使用情况的shell脚本
- 用来查看linux内存使用情况的shell脚本
- Shell脚本查看进程内存真实占用情况
- 使用shell脚本采集系统cpu、内存、磁盘、网络等信息
- shell脚本监控linux系统内存使用情况的方法(不使用nagios监控linux)
- 使用shell脚本采集系统cpu、内存、磁盘、网络等信息
- 如何通过shell脚本统计apache使用多少内存
- 利用shell脚本来监控linux系统的负载与CPU和内存使用情况
- 如何在shell脚本中使用变量
- 使用shell 脚本对 Linux 系统进程的CPU使用率与内存资源进行监控
- 使用shell脚本监控共享池内存碎片
- 查看进程内存真实占用情况的脚本
- 《使用shell位置变量进行目录文件的备份小脚本》
- shell脚本监控linux系统内存使用情况的方法(不使用nagios监控linux)
- linux 下用shell 查看内存使用情况
- BAT脚本查看相应程序运行时内存使用
- shell脚本里函数定义和变量使用
- shell脚本监控系统负载、CPU和内存使用情况