Shell script: a script that calculates the memory and usage of the local machine.

Source: Internet
Author: User

Author: gnuhpc
Source: http://www.cnblogs.com/gnuhpc/

#! /Bin/bash #################################### ###################################### Author: futuristic daemon # created time: Thu 19 Nov 2009 10:57:15 pm CST # file name: checkmem. sh # description: ######################################## ################################## fetch and process memory information [-F/proc/meminfo] & amp; # first judge whether the file exists #-e indicates the mode, it is often used to protect the pattern starting with a broken number. #-W indicates full match. #-I ignore case sensitivity. #-D specifies the delimiter, and-F indicates the domain retrieved according to the delimiter, 2-indicates the domain 2 and later buffers = 'grep-We 'buffers'/proc/meminfo | cut-d'-F2-| tr-d "[A-Z] [a-Z] "'cached = 'grep-We 'cached '/proc/meminfo | cut-d'-F2-| tr-d" [A-Z] [A-z] "'memfree = 'grep-ie 'memfree'/proc/meminfo | cut-d'-F2-| tr-d" [A-Z] [A-Z] "' memtotal = 'grep-ie 'memtotal'/proc/meminfo | cut-d'-F2-| tr-d "[A-Z] [A-Z]" 'swapcached =' grep-ie 'swapcached'/proc/meminfo | cut-d'-F2-| tr-d "[A-Z] [A-Z]" 'swapfree = 'grep-ie 'swapfree'/proc/meminfo | cut-d'-F2-| tr-d "[A-Z] [A-Z]" 'swaptotal = 'grep-ie 'swaptotal' /proc/meminfo | cut-D ''-F2-| tr-d" [A-Z] [A-Z] "'} memused =" $ ($ memtotal -$ memfree) -$ cached)-$ buffers)/1024) "memtotal =" $ ($ memtotal/1024) "memfree =" $ ($ memtotal-$ memused )) "memper =" $ ($ memused * 100)/$ memtotal )) "[" $ swaptotal "-GT" 1 "] & {swapused =" $ ($ swaptotal-$ swapfree)-$ swapcached)/1024 )) "swaptotal =" $ ($ swaptotal/1024) "swapfree =" $ ($ swaptotal-$ swapused) "Swapper =" $ ($ swapused * 100) /$ swaptotal )) "} | {swapused =" 0 "swaptotal =" 0 "Swapper =" 0 "} # display the information/bin/ECHO/bin/echo" Memory "/bin/echo "used: $ memused MB "/bin/echo" free: $ memfree MB "/bin/echo" Total: $ memtotal MB "/bin/ECHO/bin/echo" Swap "/bin/echo" used: $ swapused MB "/bin/echo" free: $ swapfree MB "/bin/echo" Total: $ swaptotal MB "/bin/echo

 

Author: gnuhpc

Source: http://www.cnblogs.com/gnuhpc/

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.