Setting up the "Find" command cron / bash script, email if any results?

I would like to set up a cron job that checks for eg. every 24 hours to see if there is a "find" command like the one below (which checks the shell's cracking scripts) has the following results:

find /home/username/public_html -type f -print0 | xargs -0 egrep '(\/tmp\/cmd(temp)?|SnIpEr_SA|(c99|r57|php)shell|milw0rm)'

      

And if there are any results, I would receive an email to the specified email address, like exam@ple.com.

Maybe something where the cron job calling the bash script runs once a day, where the find command is run through the bash script and the bash script checks the number of characters that the find command returns and sends the email if it is greater than 0. Not I'm sure this is the best approach, but this is the only one I could think of.

I don't know enough bash programming to implement this though (or any similar alternative) - what would be the implementation of this kind?

+2


a source to share


1 answer


The default cron action is to send you an email if there is output from the script Just edit your crontab (crontab -e) and add the MAILTO variable at the top.



MAILTO=exam@ple.com
30 1 * * * find /home/username/public_html -type f -print0 | xargs -0 egrep '(\/tmp\/cmd(temp)?|SnIpEr_SA|(c99|r57|php)shell|milw0rm)'

      

+5


a source







All Articles