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!
[[ $( find /folder/with/files -type f | wc -l ) -lt 3 ]] && mail -t someone@somewhere.com -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.