开发者

How do I run a script every time I save a file in Linux?

开发者 https://www.devze.com 2023-01-05 18:09 出处:网络
How do I run a script 开发者_Go百科every time I save a file in Linux?Linux has a subsystem call inotify which can cause filesystems to report changes in the filesystem to applications.

How do I run a script 开发者_Go百科every time I save a file in Linux?


Linux has a subsystem call inotify which can cause filesystems to report changes in the filesystem to applications.

Your linux system probably has a package called incron which makes using inotify very easy. (Or search your available packages for any package whose description contains the word 'inotify').

Setting up incron is very much like setting up cron, except whereas cron executes a script at a specified time and date, incron executes a script whenever a specified file or directory changes.

PS. On Ubuntu (for example), incron is this package and is installed with

sudo apt-get install incron


I was trying to do the same thing and ended up writing a python script to do it for me.

https://github.com/bawigga/spy

usage:

$ ./spy myscript.py
... your script output ...

$ ./spy --help
Usage: spy [OPTIONS] [WATCH]

Options:
  --version             show program's version number and exit
  -h, --help            show this help message and exit
  -c, --clear           clear the screen after each execution
  -e COMMAND, --exec=COMMAND
                        path to the program to execute
  -i INTERVAL, --interval=INTERVAL
                        (in seconds) set the time interval to check for file
                        modifications
0

精彩评论

暂无评论...
验证码 换一张
取 消