Recursive use of variables in shell scripts--Real memory usage view scripts

Source: Internet
Author: User


When a variable is evaluated in a script, you need to add a [] to the outside and set a $


[email protected] tmp]# cat real_mem_used01.sh
#!/bin/bash
Total= ' Free-g|grep Mem |awk ' {print $} '
Used= ' Free-g|grep Mem |awk ' {print $} '
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%
[Email protected] tmp]#
[Email protected] tmp]# sh real_mem_used01.sh
12%
[Email protected] tmp]#

Method Two:

[email protected] tmp]# cat aa.sh
#!/bin/bash
Real_used= ' Free-g|grep cache |grep ': ' |awk ' {print $} '
Total= ' Free-g|grep Mem|awk ' {print $} '
awk ' begin{printf '%.2f\n ', (' $Real _used '/' $Total ') *100} '
[Email protected] tmp]# sh aa.sh
10.64
[Email protected] tmp]#

Recursive use of variables in shell scripts--Real memory usage view scripts

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.