Sponsored Content
Top Forums Shell Programming and Scripting Nagios script to get total and free memory Post 302885458 by berveglieri on Sunday 26th of January 2014 01:32:30 PM
Old 01-26-2014
Thx for replay Mr Zaxxon, i changed my code.
I'm just confused how to call MEMCAL function only if user type 2 int parameters like check_ram -w 80 -c 90.
how can i check if the two parameters has int values and only after check it call the function?
I'm still trying but i can't find a solution.

Code:
#!/bin/bash
  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 warn=$1
 24 crit=$2
 25   
 26 full=$(free -m | awk 'NR==2 {print $2}')
 27 used=$(free -m | awk 'NR==3 {print $3}')
 28 free=$(free -m | awk 'NR==3 {print $4}')
 29 
 30 percent=$(( ($free*100)/$full))
 31 
 32 #calculation of the memory
 33 MEMCALC(){
 34  
 35 if [ $used -lt $(( ($full*80)/100 )) ] || [ $free -lt $(( ($full*80)/100 )) ];then
 36 echo "OK: using $used MB, you still have $percent% of free memory"
 37 exit 0
 38 
 39 elif [ $used -ge $(( ($full*80)/100 )) ] || [ $used -lt $(( ($full*90)/100 )) ];then
 40 echo "WARNING: using $used MB, you have $percent% of free memory"
 41 exit 1
 42 
 43 elif [ $used -ge $(( ($full*90)/100 )) ];then
 44 echo "CRITICAL: using $used MB, you only have $percent% of free memory"
 45 exit 2
 46 
 47 else
 48 echo "unknow"
 49 exit 3
 50 fi
 51 }
 52 
 53 case $1 in
 54         -h | --help)HELP;;
 55         *)HELP;;
 56 esac

 

10 More Discussions You Might Find Interesting

1. Filesystems, Disks and Memory

Total Memory/Swap Memory

I need to put a program together to determine the total, available memory and total and available swap on unix machines. I have been searching for weeks and I seem to run into dead ends. Every unix platform I look at has a different way to determine memory info. Any sugggestions or new... (4 Replies)
Discussion started by: ghe1
4 Replies

2. AIX

How to check free/total Memory in AIX

Friends , i have a question how to check the total memomry and free memory in AIX, We have vmstat ,svmon and topas commands.Which command among the will give the true figure. (6 Replies)
Discussion started by: vimalbhan
6 Replies

3. Solaris

How to find Total and Free Physical Memory and Logical Memory in SOLARIS 9

Hi, Im working on Solaris 9 on SPARC-32 bit running on an Ultra-80, and I have to find out the following:- 1. Total Physical Memory in the system(total RAM). 2. Available Physical Memory(i.e. RAM Usage) 3. Total (Logical) Memory in the system 4. Available (Logical) Memory. I know... (4 Replies)
Discussion started by: 0ktalmagik
4 Replies

4. Solaris

how to get the more memory free space (see memory free column)

Hi all, Could please let me know how to get the more memory free space (not added the RAM) in local zone. -bash-3.00# vmstat 2 5 kthr memory page disk faults cpu r b w swap free re mf pi po fr de sr s0 s1 s1 s1 in sy cs us sy... (3 Replies)
Discussion started by: murthy76
3 Replies

5. Shell Programming and Scripting

Calculate total space, total used space and total free space in filesystem names matching keyword

Good afternoon! Im new at scripting and Im trying to write a script to calculate total space, total used space and total free space in filesystem names matching a keyword (in this one we will use keyword virginia). Please dont be mean or harsh, like I said Im new and trying my best. Scripting... (4 Replies)
Discussion started by: bigben1220
4 Replies

6. Solaris

command to get the total disk space (available + free)

is there a command to get the total disk space (available + free) on the solaris server ? thanks (3 Replies)
Discussion started by: sudhiroracle
3 Replies

7. Red Hat

Total Memory

Hi, I have a strange issue where the total memory on the server is showing low. At the moment 8 GB of memory is installed and only 3 GB is showing on the shell prompt. I am using the commands free -m and vmstat to check the memory. Please help me out in identifying the issue. With regards... (3 Replies)
Discussion started by: shabu
3 Replies

8. UNIX for Advanced & Expert Users

Out of Memory error when free memory size is large

I was running a program and it stopped and showed "Out of Memory!". at that time, the RAM used by this process is around 4G and the free memory size of the machine is around 30G. Does anybody know what maybe the reason? this program is written with Perl. the OS of the machine is Solaris U8. And I... (1 Reply)
Discussion started by: lilili07
1 Replies

9. AIX

How much total and free memory I have in my aix 5.3 server?

good morning, how I can know how much total and free memory I have in my AIX 5.3 server, and this is shown in megabytes or gigabytes? Thank you very much. (4 Replies)
Discussion started by: systemoper
4 Replies

10. Shell Programming and Scripting

Calculate total memory using free -m

Hi I am trying to calculate memory used by Linux System free -m total used free shared buffers cached Mem: 32109 31010 1099 0 3600 7287 -/+ buffers/cache: 20121 11987 Swap: 10239 1282 8957 Now according to my requirement Im calculating memory using below cmd free -m | awk 'NR==3{printf... (2 Replies)
Discussion started by: sam@sam
2 Replies
ATF-SH(1)						    BSD General Commands Manual 						 ATF-SH(1)

NAME
atf-sh [-s shell] -- interpreter for shell-based test programs SYNOPSIS
atf-sh script DESCRIPTION
atf-sh is an interpreter that runs the test program given in script after loading the atf-sh(3) library. atf-sh is not a real interpreter though: it is just a wrapper around the system-wide shell defined by ATF_SHELL. atf-sh executes the inter- preter, loads the atf-sh(3) library and then runs the script. You must consider atf-sh to be a POSIX shell by default and thus should not use any non-standard extensions. The following options are available: -s shell Specifies the shell to use instead of the value provided by ATF_SHELL. ENVIRONMENT
ATF_LIBEXECDIR Overrides the builtin directory where atf-sh is located. Should not be overridden other than for testing purposes. ATF_PKGDATADIR Overrides the builtin directory where libatf-sh.subr is located. Should not be overridden other than for testing purposes. ATF_SHELL Path to the system shell to be used in the generated scripts. Scripts must not rely on this variable being set to select a specific interpreter. EXAMPLES
Scripts using atf-sh(3) should start with: #! /usr/bin/env atf-sh Alternatively, if you want to explicitly choose a shell interpreter, you cannot rely on env(1) to find atf-sh. Instead, you have to hardcode the path to atf-sh in the script and then use the -s option afterwards as a single parameter: #! /path/to/bin/atf-sh -s/bin/bash ENVIRONMENT
ATF_SHELL Path to the system shell to be used in the generated scripts. SEE ALSO
atf-sh(3) BSD
September 27, 2014 BSD
All times are GMT -4. The time now is 02:42 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy