Search code examples
emailinotifymutt

how to send an email alert if a folder is modified


I want to get an email alert if a certain folder is modified but how do I pipe the output from the command so it sends an email not just show the changes to the folder in the terminal?

something like the following but... gives an error on the email part

inotifywait -m /home/tom -e create -e moved_to |
    while read path action file; do
        echo "The file '$file' appeared in directory '$path' via '$action'"
        | /usr/bin/Mail -s "notify" "[email protected]"
    done

Solution

  • Could it be you simply missed the semicolon before done?

    This line works for me (note I also used mutt instead of Mail):

    inotifywait -m /home/tom -e create -e moved_to | while read path action file; do echo "The file '$file' appeared in directory '$path' via '$action'" | /usr/bin/mutt -s "notify" "[email protected]" ;done