I'm using 'find' at the end of a script to email me any .log files in the current directory that have been modified in the last 6 hours. I need this because the file names change so I can't be any more specific than requesting the recently changed ones.


for file in `find ./*.log -type f -mmin -360` ; do mail -s "MY LOG FILE - $file" me@mydomain.com  < $file ; done

...and it works sometimes, but more often it doesn't work even when I know there is a file in the directory that fits the criteria (having just been modified).

Any ideas why it's not working consistently for me?

migrated from serverfault.com Mar 22 '14 at 7:54

This question came from our site for system and network administrators.

  • how large are those modified files? depending on your mail setup you might have a limit there, though you should be able to tell by checking your mail logfiles. – Dennis Nolte Mar 21 '14 at 11:27

Try this :

find ./*.log -type f -mmin -360 | \
     xargs -n 1 -I % sh -c 'mail -s "MY LOG FILE - %" me@mydomain.com  < %'

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.