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/