inotify+rsync+mutt+msmtp实现linux文件或者目录自动更新
[root@localhost ~]# vi mon.sh 监控目录 #!/bin/bash clear src=更新目录地址 /usr/local/inotify/bin/inotifywait -m -r -d -o /tmp/monitor.log --timefmt '%F%T' --format '%T%w%f%e' -e modify,attrib,move,close_write,create,delete,delete_self $src #!/bin/bash src=更新目录地址 des1=static user1=www1 host1="192.168.0.185" /usr/local/bin/inotifywait -m -r -d -o /tmp/monitor.log --timefmt '%F%T' --format '%T%w%f%e' -e modify,attrib,move,close_write,create,delete,delete_self $src| while read DIRECTORY EVENT FILE do rsync -vzrtopg --delete --progress 更新目录www1@192.168.0.185::static --password-file=/etc/www1.pwd echo "${files} was rsynced" >> /tmp/rsync.log 2>&1 done -m, 即--monitor,表示始终保持事件监听状态。 -r, 即--recursive,表示递归查询目录。 -q, 即--quiet,表示打印出监控事件。 -e, 即--event,通过此参数可以指定要监控的事件,常见的事件有modify、delete、create、attrib等 --timefmt:指定时间的输出格式 --format:指定变化文件的详细信息 [root@localhost ~]# vi send.sh #!/bin/bash clear path_f=/tmp/monitor.log email=31279641@qq.com function mutt_send() { /usr/local/mutt/bin/mutt -s "WARN" -c 312779641@qq.com</tmp/monitor.log } if [ -s $path_f ]; then echo "mail send.......";sleep 1 /usr/local/mutt/bin/mutt -s "WARN" -c 312779641@qq.com</tmp/monitor.log fi cat /dev/null > $path_f [root@localhost ~]# ll 总用量 388 -rw-r--r-- 1 root root 380 9月 17 18:13 2.sh drwxrwxrwx 6 1000 1000 4096 9月 18 09:23 inotify-tools-3.14 -rw-r--r-- 1 root root 358772 3月 14 2010 inotify-tools-3.14.tar.gz -rw-r--r-- 1 root root 221 9月 18 09:24 mon.sh drwxr-xr-x 7 1000 1000 4096 9月 17 15:23 msmtp-1.4.31 drwxr-xr-x 9 3121 3121 12288 9月 17 15:25 mutt-1.4.2.3 -rw------- 1 root root 114 9月 18 09:11 nohup.out -rw-r--r-- 1 root root 323 9月 18 09:37 send.sh (编辑:佛山站长网) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |