如果修改了文件夹,如何发送电子邮件警报

how to send an email alert if a folder is modified

如果某个文件夹被修改,我想收到一封电子邮件警报,但我如何通过管道传输命令的输出,以便它发送一封电子邮件,而不仅仅是在终端中显示对文件夹的更改?

类似于以下内容,但是...在电子邮件部分出现错误

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@12345mail.com"
    done

会不会是你漏掉了done前面的分号?

这条线对我有用(注意我也使用 mutt 而不是 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@12345.com" ;done