日韩av黄I国产麻豆传媒I国产91av视频在线观看I日韩一区二区三区在线看I美女国产在线I麻豆视频国产在线观看I成人黄色短片

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 >

linux监控目录变动

發布時間:2025/7/25 40 豆豆
生活随笔 收集整理的這篇文章主要介紹了 linux监控目录变动 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

文件監控工具 inotify-tools

在Linux下載并安裝工具 inotify-tools 。

Ubuntu 下安裝:

sudo apt-get install inotify-tools
  • 1

例子

假設工程文件都放在 src/ 中,并且想監控此文件夾中的所有文件變更、創建、刪除操作,事件發生后可執行 mvn package 進行打包。

#!/bin/bash cd `dirname $0`rebuild() {local build_lock="build.lock"local pending_lock="pending.lock"test -f $build_lock && {echo "building is in process and waiting.." >&2touch $pending_lockexit 1}touch $build_lockecho -------------------- rebuildmvn packageecho -------------------- rebuild completerm $build_locktest -f $pending_lock && {rm $pending_lockrebuild &} }main() {local folder="src/"local file_4_changes="/tmp/watch"while inotifywait -e create,modify,delete -r $folder -o $file_4_changes; dorebuild &done }; main "$@"

文件的變更歷史都在日志文件 /tmp/watch 中記錄。

///***************************************************************

使用inotify來監控文件變化。inotify是基于事件的監控,無需定時輪詢文件狀態,也無需做內核模塊hook系統調用,簡單可靠。比較好的實現是檢測到文件變化時,同時記錄下當前登陸的用戶以及當前用戶啟動的進程。不過inotify,需要kernel?2.6.13以上支持,RHEL5默認是有的,其它系統不確定。

比如:$ dnotify -rCDRM dragon_extfs/ -e echo hello&

監控dragon_extfs包括子目錄下所有改動,當發生(C創建,D刪除,R更名,M修改)等改變時執行命令echo hello


事件:
? -A, --access ? ? ? ? ? ? 目標目錄文件被訪問
? -M, --modify ? ? ? ? ? ? 目標目錄文件被改變
? -C, --create ? ? ? ? ? ? 目標目錄文件被創建
? -D, --delete ? ? ? ? ? ? 目標目錄文件被刪除
? -R, --rename ? ? ? ? ? ? 目標目錄文件被更名
? -B, --attrib ? ? ? ? ? ? 目標目錄文件被屬性修改
? ? ? ? ? ? ? ? ? ? ? ??
? -a, --all ? ? ? ? ? ? ? ?以上所有事件


參數:
? -e, --execute=COMMAND.. ?執行命令 一般情況下-e為最后一個參數,-e之后為命令argv
? -f, --file=FILE ? ? ? ? ?監控一個文件目錄列表
? -p, --processes=COUNT ? ?max number of commands to run at a time
? -q, --queue=DEPTH ? ? ? ?max depth of queue holding commands to be run
? -t, --times=COUNT ? ? ? ?exit after running the command COUNT times
? -o, --once ? ? ? ? ? ? ? same as `--times 1'
? -r, --recursive ? ? ? ? ?遞歸子目錄
? -b, --background ? ? ? ? 后臺運行
? -s, --silent ? ? ? ? ? ? 不打印信息
? ? ? --quiet ? ? ? ? ? ? ?同-s
? ? ? --help ? ? ? ? ? ? ? display this help and exit
? ? ? --version ? ? ? ? ? ?output version information and exit






總結

以上是生活随笔為你收集整理的linux监控目录变动的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。