Contact Info

Crumbtrail

ActiveXperts.com » Network Monitor » Scripts » Custom Script

disk-free.sh - ssh script by ActiveXperts Software

disk-free.sh checks available free space on a disk.

Use disk-free.sh directly from ActiveXperts Network Monitor; in the Manager's 'Monitor' menu, select 'New Check (Script)' and select disk-free.sh. Configure the required parameter, or press 'Load a working sample'.

In ActiveXperts Network Monitor, Administrators can use three different scripting languages: Powershell, VBScript and SSH.


disk-free.sh script code

#################################################################################
# ActiveXperts Network Monitor - Shell script checks
# © 1999-2015, ActiveXperts Software B.V.
#
# For more information about ActiveXperts Network Monitor and SSH, please
# visit the online ActiveXperts Network Monitor Shell Script Guidelines at:
#   http://www.activexperts.com/support/network-monitor/online/linux/
#################################################################################
# Script
#     disk-free.sh
# Description
#     Checks the available free space on a disk
# Declare Parameters
#     1) $path (string) - Path to disk
#     2) $max_size_MB (string) - Max size of disk
# Usage
#     disk-free.sh <path> <max_size_MB>
# Sample
#     disk-free.sh /dev/sda1 60
#################################################################################

#!/bin/sh

# Macro definitiions
PART=$1
MSIZE=$2
DISKS=`df -T | awk ' NR!=1 { print $0; }'`

# Validate number of arguments
if [ $# -ne 2 ] ; then
  echo "UNCERTAIN: Invalid number of arguments - Usage: disk-free <path> <max_size_MB>"
  exit 1
fi

# Try to get disk information
if [[ -z $DISKS ]]; then
  echo "UNCERTAIN: Unable to get disk information."
  exit 1
fi

set -- $DISKS
i=1

# Check for the free space on the partition specified
while [[ -n ${!i} ]]
do
  if [ ${!i} == $PART ] ; then
    size=`expr $i + 2`
    used=`expr $i + 3`
    free=`expr $i + 4`

    if [[ ${!free} -ge $MSIZE ]] ; then
      echo "SUCCESS: Free disk space on drive $PART=[${!free} MB], minimum required=[$MSIZE MB] DATA:${!free}"
    else
      echo "ERROR: Free disk space on drive $PART=[${!free} MB], minimum required=[$MSIZE MB] DATA:${!free}"
    fi	
  fi
  i=`expr $i + 7`
done

# Give a warning if the partition does not exist
if [ -z $size ] ; then
  echo "UNCERTAIN: Partition $PART does not exist"
fi