最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

shell腳本實(shí)現(xiàn)實(shí)時檢測文件變更

 更新時間:2015年05月21日 10:23:27   投稿:junjie  
這篇文章主要介紹了shell腳本實(shí)現(xiàn)實(shí)時檢測文件變更,本文直接給出實(shí)現(xiàn)代碼和使用方法,以及svn下的實(shí)現(xiàn)代碼,需要的朋友可以參考下

使用python做web開發(fā),現(xiàn)在流行使用uwsgi調(diào)用python程序,但是使用uwsgi一段時間發(fā)現(xiàn)有一個弊端,就是每次更改源代碼后必須重啟uwsgi才能生效,包括更改模板文件也是,我是個懶人,再經(jīng)過一段時間反復(fù)的更改-重啟后我終于忍受不了,決定寫一個腳本來定時程序目錄的文件改動,并及時自動重啟uwsgi,來解放我的雙手可以不用理會這些瑣碎的重啟工作. 用了點(diǎn)時間來編寫了一個腳本用來判斷是否更改,然后判斷是否需要重啟uwsgi.

下面放出腳本內(nèi)容:

#!/bin/bash
# Author   : cold
# Filename  : checkchange.sh
# Useage   : sh checkchange.sh [dir]
checkisdir()
    # Have one argument
    # The argument is a directory
    for i in `ls $1 | sed -e 's/ /\n/g'`
    do
        if [ -d $1/$i ]
        then
            if [ $i == "bin" -o $i == "lib" -o $i == "include" ]  # 不想檢測的目錄(這里是使用virtualenv生成的環(huán)境文件)
            then
                continue
            fi
            dir="$1/$i"
            checkisdir $dir
        else
            files=$files'\n'$1'/'$i
        fi
    done
    echo -e $files
}
while true
do
    if [ -e /tmp/stat.tmp ]
    then
        for i in `checkisdir $1`
        do
            if [ -e /tmp/patch.tmp ]
            then
                stat $i | grep Change > /tmp/nstat.tmp
                rm -f /tmp/patch.tmp
                continue
            fi
            stat $i | grep Change >> /tmp/nstat.tmp
        done
        diff /tmp/stat.tmp /tmp/nstat.tmp > /tmp/patch.tmp
        if [ $? -eq 0 ]
        then
            sleep 10
        else
            /etc/init.d/uwsgi.py restart          # 將此處更改為想要做的操作
            patch /tmp/stat.tmp /tmp/patch.tmp
        fi
    else
        for i in `checkisdir $1`
        do
            stat $i | grep Change >> /tmp/stat.tmp
        done
        continue
    fi
done

這里主要測試變更后重啟uwsgi,使用方法:我的bottle程序在/code/python下:

復(fù)制代碼 代碼如下:

sh checkchange.sh /code/python &

如果使用svn可以參考下面代碼:

#!/bin/bash
# Author    : cold
# Filename   : checkupdate.sh
# Describle   : To Check update of svn

while true
do
    cd /code/python
    svn up | grep At > /dev/null 2>&1
    if [ $? -eq 0 ]
    then
        sleep 30
    fi

    svn up | grep Updated > /dev/null 2>&1
    if [ $? -eq 0 ]
    then
        /etc/init.d/uwsgi.py restart
    fi
done

相關(guān)文章

最新評論

万载县| 辛集市| 鄂尔多斯市| 乐至县| 东至县| 云南省| 阳东县| 寿宁县| 睢宁县| 宁海县| 辽阳县| 双江| 松原市| 盐津县| 津南区| 于都县| 高要市| 静海县| 拜城县| 元江| 静安区| 那曲县| 潮安县| 玛曲县| 揭西县| 连南| 航空| 乐陵市| 汉寿县| 遵义县| 滕州市| 苍溪县| 江陵县| 清水河县| 大庆市| 清苑县| 安新县| 夏津县| 苍南县| 西峡县| 高安市|