本教學將說明如何在 Linux/UNIX 系統上,針對特定的檔案目錄所發生的任何異動,作即時性的監控及通報。
系統環境:
其他解決方案:
另一個解決方案是軟體 in otify-tools,這工具可以監控特定目錄的檔案異動情形(Linux 2.6.13 以上才有支援),以下連結的範例是用在特定目錄下,一旦有檔案或目錄的異動,立即呼叫 rsync 的備份 script。
How to use inotify-tools to trigger scripts on filesystem events
php使用inotify實現陣列處理
安裝 Integrit
下載安裝檔
http://sourceforge.net/projects/inte...ar.gz/download
編譯安裝
tar xzf integrit-4.1.tar.gz
cd integrit-4.1
./configure --prefix=/opt/integrit
make
make install
新增設定檔 /etc/integrit.conf
known=/root/known.cdb
current=/root/current.cdb
root=/mnt/your/directory/path
Tips:
known 基準系統狀態資料庫
current 目前系統狀態資料庫
root 監控的目錄
該目錄若是第一次作監控,需要先建立基準狀態資料庫,指令如下:
/opt/integrit/sbin/integrit -u -C /etc/integrit.conf –N /root/known.cdb
檢查目錄的狀態
/opt/integrit/sbin/integrit -u -c -C /etc/integrit.conf
Tips:
-u update
-c 執行檢查
-C 設定擋路徑
監控的 perl script
功能:
- 目錄內檔案的新增、刪除、變更(包含權限) 等異動發生時,都會被偵測出來。
- 郵件通知使用系統的 mail 指令,無須加裝任何 perl module。
內容:
reference to undefined name 'syntax' Exception of type 'MindTouch.Deki.Script.Runtime.DekiScriptUndefinedNameException' was thrown. (click for details)Callstack:
at User:Alang/IT_專案工作/即時監控檔案目錄的異動
MindTouch.Deki.Script.Runtime.DekiScriptUndefinedNameException: reference to undefined name 'syntax' Exception of type 'MindTouch.Deki.Script.Runtime.DekiScriptUndefinedNameException' was thrown.
at MindTouch.Deki.Script.Compiler.DekiScriptExpressionEvaluation.Visit (MindTouch.Deki.Script.Expr.DekiScriptVar expr, DekiScriptExpressionEvaluationState state) [0x00000] in <filename unknown>:0
at MindTouch.Deki.Script.Expr.DekiScriptVar.VisitWith[DekiScriptExpressionEvaluationState,Range] (IDekiScriptExpressionVisitor`2 visitor, DekiScriptExpressionEvaluationState state) [0x00000] in <filename unknown>:0
at MindTouch.Deki.Script.Compiler.DekiScriptExpressionEvaluation.Evaluate (MindTouch.Deki.Script.Expr.DekiScriptAccess expr, DekiScriptExpressionEvaluationState state, Boolean evaluateProperties) [0x00000] in <filename unknown>:0
at MindTouch.Deki.Script.Compiler.DekiScriptExpressionEvaluation.Visit (MindTouch.Deki.Script.Expr.DekiScriptAccess expr, DekiScriptExpressionEvaluationState state) [0x00000] in <filename unknown>:0
at MindTouch.Deki.Script.Expr.DekiScriptAccess.VisitWith[DekiScriptExpressionEvaluationState,Range] (IDekiScriptExpressionVisitor`2 visitor, DekiScriptExpressionEvaluationState state) [0x00000] in <filename unknown>:0
at MindTouch.Deki.Script.Compiler.DekiScriptExpressionEvaluation.Visit (MindTouch.Deki.Script.Expr.DekiScriptCall expr, DekiScriptExpressionEvaluationState state) [0x00000] in <filename unknown>:0
at MindTouch.Deki.Script.Expr.DekiScriptCall.VisitWith[DekiScriptExpressionEvaluationState,Range] (IDekiScriptExpressionVisitor`2 visitor, DekiScriptExpressionEvaluationState state) [0x00000] in <filename unknown>:0
at MindTouch.Deki.Script.Compiler.DekiScriptExpressionEvaluation.Visit (MindTouch.Deki.Script.Expr.DekiScriptSequence expr, DekiScriptExpressionEvaluationState state) [0x00000] in <filename unknown>:0
at MindTouch.Deki.Script.Expr.DekiScriptSequence.VisitWith[DekiScriptExpressionEvaluationState,Range] (IDekiScriptExpressionVisitor`2 visitor, DekiScriptExpressionEvaluationState state) [0x00000] in <filename unknown>:0
at MindTouch.Deki.Script.Compiler.DekiScriptExpressionEvaluation.Visit (MindTouch.Deki.Script.Expr.DekiScriptReturnScope expr, DekiScriptExpressionEvaluationState state) [0x00000] in <filename unknown>:0