Anonymous Anonymous - 2 months ago
126 0

When threshold (80%) is met an email will be send. This script is tested on a Centos 7 machine.

Bash

Bash script to check memory usage

#!/bin/bash
MEMORY_USAGE=$(free | grep Mem | awk '{print $3/$2 * 100.0}')
echo $MEMORY_USAGE
intmemory=${MEMORY_USAGE%.*}
echo $intmemory

if (( $intmemory > 80 ))
then
mail -s "MEMORY USAGE server is high!" my@email.com <<< "Current usage: $MEMORY_USAGE"
fi