1、首先确保环境有安装inotify-tools工具
http://www.daileinote.com/computer/linux_cmd/43
这里提供一个百度的压缩包
链接:https://pan.baidu.com/s/1wp8gsPC7h0qpEj-Ge4xjpQ
提取码:8888
如果安装校验是否安装成功时,其中有报错,
inotifywait: error while loading shared libraries: libinotifytools.so.0: cannot open shared object file: No such file or directoryxxx
可以执行以下命令
**解决方法:** 32位系统:ln -s /usr/local/lib/libinotifytools.so.0 /usr/lib/libinotifytools.so.0 64位系统:ln -s /usr/local/lib/libinotifytools.so.0 /usr/lib64/libinotifytools.so.0
2.编写监控脚本
#!/bin/bash TARGET_FILE="/easv82/easv82app/eas/server/lib/sp/example.txt" COPY_TO="/easv82/easv82app/eas/server/deploy/fileserver.ear/easWebClient/lib/sp" LOG_FILE="/easv82/copyJar.log" # 确保备份目录存在 mkdir -p "$COPY_TO" while inotifywait -e modify "$TARGET_FILE"; do USER=$(whoami) TIMESTAMP=$(date +"%Y-%m-%d %H:%M:%S") # 将修改后的文件复制到备份目录 cp -f "$TARGET_FILE" "$COPY_TO/" # 记录文件修改信息到日志文件 echo "File $TARGET_FILE was modified by $USER at $TIMESTAMP , COPY to $COPY_TO" >> "$LOG_FILE" done
我这里是将example.txt作为监控对象,将修改后的文件复制到copy_to的路径下,并将更新日志记录到LOG_FILE当中
标签:复制到,文件,libinotifytools,lib,so.0,修改,FILE,COPY From: https://www.cnblogs.com/ketoli/p/18034232