Send e-mail when file modified

mailx

Download mailx (openSUSE is the distribution of my server) and install it.

$ make PREFIX=/public/home/zhangxin/softwares/mailx SYSCONFDIR=/public/home/zhangxin/softwares/mailx/etc
$ make install UCBINSTALL=/usr/bin/install PREFIX=/public/home/zhangxin/softwares/mailx SYSCONFDIR=/public/home/zhangxin/softwares/mailx/etc

Get your authorization code and edit mailx/etc/nail.rc

set smtp=smtp.qq.com
set smtp-auth-user="[email protected]"
set smtp-auth-password="authorization_code"
set smtp-auth=login

Test:

$ echo "haha" | mailx -v -s "Test" [email protected]

Usage:

mailx -T FILE -u USER -h hops -r address -s SUBJECT -a FILE -q FILE -f FILE -A ACCOUNT -b USERS -c USERS -S OPTION users

inotifywait

Download inotifywait from here and install it.

#!/bin/bash
inotifywait -m /public/software/anaconda/requirements.txt --timefmt '%d/%m/%y %H:%M' --format '%T %w %f' -e modify -e move -e delete_self | while read date time action dir file; do
FILECHANGE=${dir}${file}
echo "At ${time} on ${date}, file $FILECHANGE was touched via '$action'" | mailx -s "requirements" -a /public/software/anaconda/requirements.txt [email protected]
done

Explanation:

-m|--monitor Keep listening for events forever. Without
this option, inotifywait will exit after one
event is received.
-e|--event <event1> [ -e|--event <event2> ... ]
Listen for specific event(s). If omitted, all events are
listened for.

Powered by Hexo and Hexo-theme-hiker

Copyright © 2013 - 2019 Dreambooker All Rights Reserved.

UV : | PV :