Contact Info

Crumbtrail

ActiveXperts.com » Network Monitor » Scripts » Custom Script

file-count.sh - ssh script by ActiveXperts Software

file-count.sh counts the number of files in a directory

Use file-count.sh directly from ActiveXperts Network Monitor; in the Manager's 'Monitor' menu, select 'New Check (Script)' and select file-count.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.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.sh
# Description
#     Counts the number of files in the specified directory
# Declare Parameters
#     1) path (string) - Path to file
#     2) max_allowed (int) - Max Allowed files
# Usage
#     file-count.sh <path> <max_allowed>
# Sample
#     file-count.sh /home/activexperts/folder 20
#################################################################################

#!/bin/sh

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

# Count files
COUNT=0;
COUNT=`find $1 -maxdepth 1 -type f -print| wc -l | awk '{ print $1 }'`

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