Bash script to email when wc -l count is below 3

1k views Asked by At

Please, can you help me with a script that counts something (wc -l) and when the count is below 3 the script emails me.

Thank you!

1

There are 1 answers

1
tvm On BEST ANSWER
[[ $( find /folder/with/files -type f | wc -l ) -lt 3 ]] && mail -t [email protected] -s Problem <<< "Less than three files."

Find and wc -l return the count of files and then [[ evaluates if the count is lees than three. If this evaluates to true and returns zero exit status, next command after && is executed.

If the mail environment is set up correctly, mail with given subject and message will be sent.