to find larger files than 4GB recursively within a directory.

Issue #527 closed
mohit.deokar created an issue

Hello,

monit is a great tool. i want to prepare a custom script that will provide me data of the files which are greater than 4GB and also send an alert for the same. here i m facing difficulty. i have prepare a small script for this.

#!/bin/bash
FOLDER_PATH="/U01/iAnalyze/contexts/iAnalyze/ConfigFiles/COMPANY_DATA/"
find $FOLDER_PATH -type f -printf '%s %p\n'| sort -nr | head -n 50 | awk '$1 > 4294967296' > /U01/Dumps/out.log
FILE="out.log"
if [ -s "$FILE" ];
then
exit
fi

As per the script ( consist of space consumed by file in bytes and the location of the file )the output is getting re-directed to out.log file, which is working fine.

output of out.log when i run this script manually.

3235217807 /U01/iAnalyze/contexts/iAnalyze/ConfigFiles/COMPANY_DATA/Aramark/export_reports/yeung-chi-kong@aramark.co.uk/EXP_1482234936540.csv

In monit i have done below configuration calling above script through monit

check program hwtest with path "/U01/Dumps/test22"
    if status = 1 then alert

but when i restart monit, monit does not throws any alert (always shows its status as OK), even if the mentioned directory contains files more than 4GB. i should receive an alert if out.log contains any data. do i require any modification in my script or in my monit configuration.

Regards Mohit.D

Comments (5)

  1. Tildeslash repo owner

    Hello,

    based on your monit configuration: the check program will send alert if the program's exit status is 1 ... the script however calls just "exit" - this will return the exit status of last command - in this case "find", which will be 0. The "exit" in the script should be modified to "exit 1".

  2. mohit.deokar Account Deactivated reporter
    • changed status to open

    Hello,

    i have made some changes in my script. as my previous one is not working. i want monit to alert or show status failed alert if out.log file contains any data.

    script name = four.sh

    #!/bin/bash if [ -s "/U01/Dumps/out.log" ] then exit 1 fi =========================

    configuration under monit .

    check program four with path "/U01/Dumps/four.sh" if status != 1 then alert =============================

    currently it is showing me status failed even there is no data under out.log file.

    kindly provide suggestion.

  3. Tildeslash repo owner

    Your script will alert if exit status is not 1 ... but it returns 1 only IFF /U01/Dumps/four.sh exists and has size > 0 - otherwise it'll return 0 by default (when exit command is missing).

    This issue is not about monit, but shell programming - please test your scripts with $? to see what they return and set the status test accordingly.

  4. Log in to comment