folder-size.sh - ssh script by ActiveXperts Software
folder-size.sh checks the size of a directory on a host.
Use folder-size.sh directly from ActiveXperts Network Monitor; in the Manager's 'Monitor' menu, select 'New Check (Script)' and select folder-size.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.
folder-size.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 # folder-size.sh # Description # Checks the size of a directory in Kilo Bytes # Declare Parameters # 1) directory (string) - Directory to check # 2) max_size_MB (int) - Size of the directory in MegaBytes # Usage # folder-size.sh <directory> <max_size_MB> # Sample # folder-size.sh /home/user 30 ################################################################################# #!/bin/sh # Validate number of arguments if [ $# -ne 2 ] ; then echo "UNCERTAIN: Invalid number of arguments - Usage: folder-size <directory> <max_size_MB>" exit 1 fi # Check the size of the directory specified if [ -d "$1" ]; then SIZEKB=`du -s "$1" | awk '{ print $1; }'` SIZEMB=$( echo "$SIZEKB / 1024" | bc ) # Round a float to an integer value SIZEMBINT=$( echo "$SIZEMB / 1" | bc ) # Round a float to an integer value MAXSIZEMB=$( echo "$2 / 1" | bc ) if [ $SIZEMBINT -le $MAXSIZEMB ] ; then echo "SUCCESS: Size of directory=[$SIZEMBINT MB], maximum allowed=[$MAXSIZEMB MB] DATA:$SIZEMBINT" else echo "ERROR: Size of directory=[$SIZEMBINT MB], maximum allowed=[$MAXSIZEMB MB] DATA:$SIZEMBINT" fi else echo "UNCERTAIN: $1 is not a directory" fi