保存文件时如何自动运行脚本文件?

さむら*_*むらい 3 linux

我正在 linux 服务器上编辑一个项目。每次更改源代码时,我都必须运行一个 shell 脚本。有没有办法将保存操作绑定到脚本文件。所以我在更改源时不需要手动运行脚本。

就像 git commit 可以挂钩 *.sh 一样。我想使用 zend studio 编辑服务器上的文件,当我保存文件时,它可以触发所需的脚本运行。

Sve*_*ven 11

inotify以 的形式使用inotify-tools并在服务器上运行包含如下内容的脚本:

#!/bin/bash
while true 
do 
    inotifywait -e modify /path/to/watched_file.txt && /bin/bash /path/to/your-script.sh
done
Run Code Online (Sandbox Code Playgroud)

这将在写入文件时执行脚本,但可能-e必须根据您的情况调整列表,请参阅man inotifywait

替代方案:只需使用git hook。