2013-01-04 136 views
1

許多其他問題與此有關的是StackOverflow。我還沒有找到任何結果沒有使用任何第三方軟件包的地方。監視目錄中沒有第三方軟件包的更改

問題是我正在使用Hetzner,他們希望允許我安裝任何軟件包。

我可以用PHP,Python和Java的(認爲非常標準的集合)

如何監視新文件的目錄(遞歸),並獲得引用到另一個文件。

我已經試過這樣的事情:

while true; do 
    last=`cat log.txt` 
    find "$UPLOAD_FOLDER"'/.' -type f > 'log.txt' 
    now=`cat log.txt` 

    diff -n <(echo "$last") <(echo "$now") >> 'queue.txt' 

    sleep 60; 
done; 

但它是不可靠的,它污染queue.txtd3ab5a等。

+1

您可以使用哪些?蟒蛇? cron的?等等。? – AlG

+0

@AlG 我可以使用PHP,Python,Java(認爲幾乎是標準集合) – andlrc

回答

1

也許最簡單的是你se標記文件:

touch markerFile 
while true 
do 
    find "$UPLOAD_FOLDER"'/.' -type f -newer markerFile >> 'queue.txt' 
    touch markerFile 
    sleep 60 
done 

可能是發現和觸摸之間的輕微競爭條件?

如意見提出一個更復雜的雙緩衝液:

touch markerFileA 
touch markerFileB 
while true 
do 
    touch markerFileB 
    find "$UPLOAD_FOLDER"'/.' -type f -newer markerFileA ! -newer markerFileB >> 'queue.txt' 
    sleep 60 
    touch markerFileA 
    find "$UPLOAD_FOLDER"'/.' -type f -newer markerFileB ! -newer markerFileA >> 'queue.txt' 
    sleep 60 
done 
+1

您可以通過在查找之前存儲當前時間,然後使用touch -t – cmh

+1

@cmh來交易假否定的誤報:另一種方式是沿着雙緩衝線在兩個標記文件之間交替。touch a; find -newer b!-newer a; sleep; touch b; find -newer a!-newer b; sleep – PleaseStand

0

你可以使用sed刪除不想要的輸出:

while :; do 

    find "$UPLOAD_FOLDER/." -type f > "log1.txt" 

    if [ -f "log2.txt" ]; then 
     diff log1.txt log2.txt | sed '/^[^<]/d;s/^< //' 

     fi 

    mv "log1.txt" "log2.txt" 

    sleep 60 

done 
+0

問題是我無法安裝任何軟件包...... :( – andlrc

+0

@NULL查看我的[更新回答](http:/ /stackoverflow.com/a/14161366/1006989),我修改了它以在沒有安裝包的情況下獲得所需的輸出 – 2013-01-04 18:03:56