file-count-sub.sh - ssh script by ActiveXperts Software
file-count-sub.sh counts the number of files in a directory and all its sub-directories.
Use file-count-sub.sh directly from ActiveXperts Network Monitor; in the Manager's 'Monitor' menu, select 'New Check (Script)' and select file-count-sub.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.
file-count-sub.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 # file-count-sub.sh # Description # Counts the number of files in the specified directory and all it's sub-directories # Declare Parameters # 1) path (string) - Path to file # 2) max_allowed (int) - Max Allowed files # Usage # file-count-sub.sh <path> <max_allowed> # Sample # file-count-sub.sh /home/activexperts/folder 20 ################################################################################# #!/bin/sh # Validate number of arguments if [ $# -ne 2 ] ; then echo "UNCERTAIN: Invalid number of arguments - Usage: file-count-sub <path> <max_allowed>" exit 1 fi # Count files in the specified directory and in it's sub directories COUNT=0; COUNT=`find $1 -type f -print | wc -l` if [ $COUNT -le $2 ]; then echo "SUCCESS: File count [$COUNT], max allowed [$2]; DATA:$COUNT"; else echo "ERROR: File count [$COUNT], max allowed [$2]; DATA:$COUNT"; fi