disk-used.sh - ssh script by ActiveXperts Software
disk-used.sh checks used space on a disk.
Use disk-used.sh directly from ActiveXperts Network Monitor; in the Manager's 'Monitor' menu, select 'New Check (Script)' and select disk-used.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-used.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-used.sh # Description # Checks the used space on a disk # Declare Parameters # 1) $path (string) - Path to disk # 2) $max_size_MB (string) - Max size of used space in Mega Bytes # Usage # disk-used.sh <path> <max_size_MB> # Sample # disk-used.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-used <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 used 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 [[ ${!used} -le $MSIZE ]] ; then echo "SUCCESS: Used disk space on drive $PART=[${!used} MB], maximum allowed=[$MSIZE MB] DATA:${!used}" else echo "ERROR: Used disk space on drive $PART=[${!used} MB], maximum allowed=[$MSIZE MB] DATA:${!used}" 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