file-size.sh - ssh script by ActiveXperts Software
file-size.sh checks the size of a file.
Use file-size.sh directly from ActiveXperts Network Monitor; in the Manager's 'Monitor' menu, select 'New Check (Script)' and select file-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.
file-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 # file-size.sh # Description # Checks the used space on a disk # Declare Parameters # 1) $file (string) - Path to file # 2) $max_size_KB (int) - Max size in KiloBytes # Usage # file-size.sh <file> <max_size_KB> # Sample # file-size.sh test.sh 10 ################################################################################# #!/bin/sh # Validate number of arguments if [ $# -ne 2 ] ; then echo "UNCERTAIN: Invalid number of arguments - Usage: file_size <file> <max_size_KB>" exit 1 fi # Check if variable is an integer if ! [ "$2" -eq "$2" ] 2>/dev/null ; then echo "UNCERTAIN: Variable [$2] must be an Integer value" exit 1 fi # Macro definitiions FILESIZEB=`du -b "$1" | awk '{ print $1; }'` # Convert Bytes to KiloBytes FILESIZEKB=$( echo "scale=2;$FILESIZEB / 1024" | bc ) # Round a float to an integer value FILESIZEKBINT=$( echo "$FILESIZEKB / 1" | bc ) # Round a float to an integer value MAXSIZEKB=$( echo "$2 / 1" | bc ) # Check if the file size is above or belove the limit specified if [ $FILESIZEKBINT -le $MAXSIZEKB ] ; then echo "SUCCESS: File size=[$FILESIZEKBINT KB], maximum allowed=[$2 KB] DATA:$FILESIZEKBINT" else echo "ERROR: File size=[$FILESIZEKBINT KB], maximum allowed=[$2 KB] DATA:$FILESIZEKBINT" fi