FileSizeMonitor for LINUX-UNIX
The script serves as an example of script that monitors size of files. This script returns the number of files that exceed the file size threshold provided to the script. In addition, the KM creates an annotation with a list of file names and their file size that exceeds the threshold.
The script takes 2 arguments:
- -p <path> (where to search for files)
- -s <file size in MB> (the file size threshold)
Configuration
Annotation details
Script details
This script is available at $PATROL_HOME\..\TRO\Conf\Scripts\Samples directory. The script content is as follows:
#!/bin/sh -f
#=======================================================================================================
# This sample script show how to monitor files which size exceeds agiven file size threshold in a given path.
# e.g. monitor all file in <path to search in> which size is greater then <file size in MB>
# the script is used with the following format:
# ./file-size-monitoring.sh -p <path to search in> -s <file size in MB>
# <path to search inB>: The path in which to search files
# <file size in MB>: The file size threshold in Megabytes, for example: 10 will yield files which size is greter then 10MB
#
# when used within a policy make sure the arguments are provided.
#=======================================================================================================
if ! [[ $# -eq 4 ]]; then
echo -e "Usage: $0 -p <path> -s <file size in MB>"
echo -e "\t<path>:\tpath to search in"
echo -e "\t<file size in MB>:\tfile size in MB"
exit -1
fi
for arg in $*
do
case $arg in
"-p")
;;
"-s")
;;
*)
if [[ $arg =~ $RegEx ]]; then
case $prevArg in
"-p")
file_path=$arg
;;
"-s")
file_size=`printf "+%sM" $arg`
;;
esac
else
echo arg=$arg
#echo "Invalid flag ignored"
fi
;;
esac
prevArg=$arg
done
files_found=`find $file_path -type f -size $file_size -exec ls -sh {} \; 2>/dev/null | awk '{print $2 " (" $1 ")"}'`
number_of_files=`echo "$files_found" | wc -l`
echo "$number_of_files"
echo "$files_found"
#=======================================================================================================
# This sample script show how to monitor files which size exceeds agiven file size threshold in a given path.
# e.g. monitor all file in <path to search in> which size is greater then <file size in MB>
# the script is used with the following format:
# ./file-size-monitoring.sh -p <path to search in> -s <file size in MB>
# <path to search inB>: The path in which to search files
# <file size in MB>: The file size threshold in Megabytes, for example: 10 will yield files which size is greter then 10MB
#
# when used within a policy make sure the arguments are provided.
#=======================================================================================================
if ! [[ $# -eq 4 ]]; then
echo -e "Usage: $0 -p <path> -s <file size in MB>"
echo -e "\t<path>:\tpath to search in"
echo -e "\t<file size in MB>:\tfile size in MB"
exit -1
fi
for arg in $*
do
case $arg in
"-p")
;;
"-s")
;;
*)
if [[ $arg =~ $RegEx ]]; then
case $prevArg in
"-p")
file_path=$arg
;;
"-s")
file_size=`printf "+%sM" $arg`
;;
esac
else
echo arg=$arg
#echo "Invalid flag ignored"
fi
;;
esac
prevArg=$arg
done
files_found=`find $file_path -type f -size $file_size -exec ls -sh {} \; 2>/dev/null | awk '{print $2 " (" $1 ")"}'`
number_of_files=`echo "$files_found" | wc -l`
echo "$number_of_files"
echo "$files_found"
Tip: For faster searching, add an asterisk to the end of your partial query. Example: cert*