Search
 
SCRIPT & CODE EXAMPLE
 

SHELL

bash memory

1 #!/bin/bash
  2 # 
  3 #
  4 #
  5 #
  6 #
  7 #
  8 #Display the name of the script
  9 SCRIPTNAME="check_memory"
 10 
 11 #Display version
 12 VERSION(){
 13 echo "Version 0.8"
 14 }
 15 
 16 #Display help
 17 HELP(){
 18 echo "$SCRIPTNAME -w <warning level> -c <critical level>"
 19 echo "example: check_ram -w 80 -c 90"
 20 }
 21 
 22 #sequence parameters
 23 w=$1 
 24 c=$2
 25   
 26 while [[ $# -gt 0 ]]
 27 do
 28 case $1 in
 29         -h | --help)VERSION;HELP;;
 30         -w) test -z $w ;if [ $? != 0 ]; then HELP ; fi; break;;
 31         -c) test -z $c ;if [ $? != 0 ]; then HELP ; fi; break;;
 32         *)VERSION;HELP; break;;
 33 esac
 34 done 
 35 
 36 full=$(free -m | awk 'NR==2 {print $2}')
 37 used=$(free -m | awk 'NR==3 {print $3}')
 38 free=$(free -m | awk 'NR==3 {print $4}')
 39 
 40 percent=$(( ($free*100)/$full))
 41 
 42 if [ $used -lt $(( ($full*80)/100 )) ] || [ $free -lt $(( ($full*80)/100 )) ];then
 43 echo "OK: using $used MB, you still have $percent% of free memory"
 44 exit 0
 45 fi
 46 
 47 
 48 
                                                                                                                                                      38,1          Fim
Comment

PREVIOUS NEXT
Code Example
Shell :: linux bash do something when file changes 
Shell :: on hotspot and wifi at the same time arch linux 
Shell :: add ssh to github 
Shell :: create user with group 
Shell :: copy ssh key from windows to linux 
Shell :: spectacle linux 
Shell :: powershell verb 
Shell :: utorrent for linux 
Shell :: docker push to private registry 
Shell :: install pug angular 
Shell :: poetry add library 
Shell :: make a new branch git 
Shell :: download mongodb ubuntu 20.04 
Shell :: python libraries for game development 
Shell :: javascript implements 
Shell :: cookiecutter 
Shell :: linux unique lines 
Shell :: add text to clipboard wsl 
Shell :: git pull a specific sha 
Shell :: how to install pipenv 
Shell :: linux mount sd card 
Shell :: grep second line 
Shell :: docker copy folder to container 
Shell :: cat first line 
Shell :: ionic capacitor ios 
Shell :: wsl import 
Shell :: git flow feature 
Shell :: macos terminal delete file 
Shell :: replace a newline using sed linux bash 
Shell :: packet10 
ADD CONTENT
Topic
Content
Source link
Name
8+3 =