主頁 > 知識(shí)庫 > shell腳本實(shí)現(xiàn)實(shí)時(shí)檢測(cè)文件變更

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

熱門標(biāo)簽:網(wǎng)站排名優(yōu)化 百度競(jìng)價(jià)排名 服務(wù)外包 鐵路電話系統(tǒng) Linux服務(wù)器 AI電銷 呼叫中心市場(chǎng)需求 地方門戶網(wǎng)站

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

這里主要測(cè)試變更后重啟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

您可能感興趣的文章:
  • 自動(dòng)化下載并檢測(cè)ftp文件備份的shell腳本
  • 用來檢測(cè)輸入的選項(xiàng)$1是否在PATH中的shell腳本
  • Shell腳本實(shí)現(xiàn)檢測(cè)Cygwin最快的鏡像站點(diǎn)
  • VBS腳本寫的Windows硬件檢測(cè)工具分享
  • Linux Shell腳本實(shí)現(xiàn)檢測(cè)tomcat
  • Shell腳本實(shí)現(xiàn)檢測(cè)進(jìn)程是否正在運(yùn)行
  • PowerShell腳本實(shí)現(xiàn)檢測(cè)網(wǎng)絡(luò)內(nèi)主機(jī)類型
  • 腳本批量檢測(cè)網(wǎng)站是否存活

標(biāo)簽:衡水 崇左 銅川 湘潭 仙桃 湖南 蘭州 黃山

巨人網(wǎng)絡(luò)通訊聲明:本文標(biāo)題《shell腳本實(shí)現(xiàn)實(shí)時(shí)檢測(cè)文件變更》,本文關(guān)鍵詞  ;如發(fā)現(xiàn)本文內(nèi)容存在版權(quán)問題,煩請(qǐng)?zhí)峁┫嚓P(guān)信息告之我們,我們將及時(shí)溝通與處理。本站內(nèi)容系統(tǒng)采集于網(wǎng)絡(luò),涉及言論、版權(quán)與本站無關(guān)。
  • 相關(guān)文章
  • 收縮
    • 微信客服
    • 微信二維碼
    • 電話咨詢

    • 400-1100-266