linux - 我可以在没有 cron 或 incron 的 Linux 服务器上连续运行 inotifywait

标签 linux shell cron inotifywait incron

我在服务器上为这个目录创建了一个 git 仓库。我想要的是每当有文件移动到目录中时,git push 将推送 repo 并提交。我试过 incrontab 来执行脚本。但似乎我的服务器不喜欢 incrontab,它每次都崩溃。

我可以在我的终端上运行这个 inotifywait。但是一旦我关闭终端,它就会停止观看。那么,有没有一种方法可以让我在 Linux 服务器上持续运行 inotifywait?

这是我的 Inotifywait 代码

while inotifywait -re modify,attrib,move,close_write,create,delete,delete_self /path/to/script.sh
    do
     cd /path/to/dir
     git pull
     git add .
     git commit -m 'updated'
     git push
     echo "done!"
    done

我真的只想使用 inotify,而不使用 cron 东西。我已经在 cron 和 incron,incrontab 上工作了很长时间。运气不好。

有人有什么想法吗?谢谢!

最佳答案

如果控制终端关闭,子进程会收到信号 - 如果没有被捕获 - 通过设计终止它们。

Hangup signal

如果你想让一个子进程不受此影响,你可以通过 nohup 命令启动它保护。

nohup command

要在后台启动命令,您可以在末尾应用(如果不是所有 shell,也是大多数 shell)。

关于linux - 我可以在没有 cron 或 incron 的 Linux 服务器上连续运行 inotifywait,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38534488/

相关文章:

linux - bash:/usr/local/bin/composer.phar 没有这种类型的文件或文件夹(ubuntu 16.04)

linux - 如何使用 bash grep 查找字符串

linux - kylix AnsiCompareStr 错误?

c - 处理具有相同主编号但唯一次编号的多个设备文件

linux - 在 Linux 上运行 .sh 脚本时出现语法错误。我究竟做错了什么?

sql - 您将如何使用Gradle处理增量SQL补丁

php - 有没有办法在从插入时间算起的一定时间后从 mysql 中删除一行

php - 执行 PHP 程序的 Cron 作业

python - 在虚拟机(Google Cloud Platform)中使用 Cron 定期运行 Python 脚本

ruby - rvm ruby​​ 更新后 Vim 不工作