Shell script realizes real-time detection file change _linux shell

Source: Internet
Author: User
Tags svn

Using Python for Web development, it is now popular to use UWSGI to invoke Python programs, but using UWSGI for a period of time to find that there is a disadvantage is that every time you change the source code must restart Uwsgi to take effect, including change template file is also, I am a lazy person, Again after a period of repeated changes-reboot after I finally can not endure, decided to write a script of the program directory of the file changes, and timely automatic restart Uwsgi, to liberate my hands do not pay attention to these trivial restart work. It took a bit of time to write a script to determine whether or not to change, and then decide whether to reboot the Uwsgi.

Here's what the script says:

#!/bin/bash # author:cold # Filename:checkchange.sh # useage:sh checkchange.sh [dir] Checkisdir () # Have O NE argument # The argument is a directory for I in ' ls $ | Sed-e ' s//\n/g ' do if [D-$1/$i] then if [$i = = "Bin"-o $i = = "Lib"-o $i = = "Inclu
            De "] # does not want to detect the directory (here is the environment file generated using VIRTUALENV) then continue fi dir=" $1/$i " Checkisdir $dir Else files= $files ' \ n '/' $i fi done echo-e $files} whil e true do if [-e/tmp/stat.tmp] then to I in ' checkisdir ' do if [-e/tmp/patch. TMP] then stat $i | grep change >/tmp/nstat.tmp rm-f/tmp/patch.tmp continue fi s Tat $i | grep change >>/tmp/nstat.tmp done diff/tmp/stat.tmp/tmp/nstat.tmp >/tmp/patch.tmp if
       [$-eq 0] Then sleep else/etc/init.d/uwsgi.py Restart # change here to the action you want to do patch /tmp/stat.tmp/tmp/patch.tmp fi else for I in ' Checkisdir $ ' do stat $i | grep change >>/tmp/stat.tmp do continue fi done

Here the main test changes after the restart Uwsgi, using the method: My bottle program under/code/python:

Copy Code code as follows:

SH Checkchange.sh/code/python &

If you use SVN, you can refer to the following code:

#!/bin/bash
# Author    : Cold
# Filename   : checkupdate.sh
# describle   : To Check update of SVN While

true
does
    Cd/code/python
    svn up | grep at >/dev/null 2>&1
    if [$-eq 0]
    th En sleep
    fi svn up

    | grep Updated >/dev/null 2>&1
    if [$?-eq 0]
    then
        /etc/in it.d/uwsgi.py Restart
    fi
done

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.