Knowledge Base

Example: free disk space (Linux)

This Example will describe how to check for free disk space ie. let LazyNanny know that there is ample disk space.
Create a scheduled trigger that will check for free disk space. Lets assume you want more than '5GB' free disk space for root /.

Create a shell script with following content

#!/bin/bash
#
# LazyNanny free disk space example
# Script will stop sending "I'm OK" messages to LazyNanny if not enough free disk space.
# command: sh /home/lazynanny/lazynanny.sh <servername> <object_id> [<mount> <free space>]
# eg.      sh /home/lazynanny/lazynanny.sh  tip2027def   3348ivf3go-8016-660
#
server=$1                           # required, servername
object_id=$2                        # required, object_id
drive=$3                            # optional, mount
freespace=$4                        # optional, min free space in GB

drive=${drive:='/'}                 # default mount '/'
freespace=${freespace:=5}           # default min frees space 5GB
LOG=`dirname "$0"`
LOG="$LOG/lazynanny.log"

if [ ! $server ] || [ ! $object_id ]; then
  echo "Missing servername and/or object_id" > $LOG
  exit 1
fi

FREE=`df -k --output=avail "$drive" | tail -n1`
result='Not enough free space'
freespace=$(($freespace*1024*1024))      #from GB to KB

if [ $FREE -gt $freespace ]; then
  result=`wget https://$server.lazynanny.com --post-data "object_id=$object_id" 2>&1`
fi;
echo $result > $LOG

Save this script as eg. /home/lazynanny/lazynanny.sh

Linux Task Scheduler (Crontab)
Create a cron task to run script every 5 minutes

  1. Login as a user (eg. lazynanny) which can create cron tasks.
  2. Start crontab for editing (eg. crontab -e)
  3. Enter: */5 * * * * /home/lazynanny/lazynanny.sh servername object_id
  4. Save crontab

Every 5 minutes the LazyNanny scheduler will start sending "I'm OK" messages to your selected* LazyNanny server (eg. tip2027def.lazynanny.com). That is, as long as there is more than 5GB of free disk space. If less then the scheduler will stop sending "I'm OK" messages to your LazyNanny server. This will make LazyNanny™ nervous and it will start sending notifications to your (list of) Recipients*.



*Free products Recipients default to account email address and default server location

Please rate this article to help us improve our Knowledge Base.

0 0