Search code examples
linuxshellcroninotifywaitincron

Can I run inotifywait continually on a Linux Server without cron or incron


I create a git repo on the server for this dir. What I want to have is whenever there is a file moves into the directory, git push will push the repo and commit. I tried incrontab to execute a script. But seems like my server doesn't like incrontab, it crashed every time.

I can run this inotifywait on my terminal. But as soon as I closed the terminal, It stops watching. So, is there a way I can run inotifywait continually on the Linux Server?

Here is my code for 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

I really want to use inotify only, without the cron things. I've been worked on cron and incron, incrontab for a long time. No luck.

Anyone have any ideas? Thanks!


Solution

  • If a controlling terminal is closed, the child processes get signals which -if not caught- terminate them by design.

    Hangup signal

    If you want a child process to be shielded from this, you can start it protecting with by the nohup command.

    nohup command

    To start a command in the background, you apply (with most, if not all shells) & at the end.